add image as comment VBA

前端 未结 6 1293
小蘑菇
小蘑菇 2021-01-16 14:54

I found this code to insert images into excel 2013 but the images are large than the cells they\'re going into. I think the best option it to load the images as comments.

6条回答
  •  时光取名叫无心
    2021-01-16 15:14

    This will add a picture as a comment quickly on the cell you are clicked on. It also resizes it to what I liked for the project I was doing.

    With Application.FileDialog(msoFileDialogFilePicker)
         .AllowMultiSelect = False          'Only one file
         .InitialFileName = CurDir         'directory to open the window
         .Filters.Clear                    'Cancel the filter
         .Filters.Add Description:="Images", Extensions:="*.png", Position:=1
         .Title = "Choose image"
    
         If .Show = -1 Then TheFile = .SelectedItems(1) Else TheFile = 0
    End With
    'No file selected
    If TheFile = 0 Then
    MsgBox ("No image selected")
    Exit Sub
    End If
    Selection.AddComment
    Selection.Comment.Visible = True
    Selection.Comment.Shape.Fill.UserPicture TheFile
    Selection.Comment.Shape.Select True
    Selection.ShapeRange.ScaleWidth 2.6, msoFalse, msoScaleFromTopLeft
    Selection.ShapeRange.ScaleHeight 2.8, msoFalse, msoScaleFromTopLeft
    ActiveCell.Comment.Visible = False
    

提交回复
热议问题