add image as comment VBA

前端 未结 6 1345
小蘑菇
小蘑菇 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条回答
  •  猫巷女王i
    2021-01-16 15:36

    I believe The following link has what you are looking for

    http://en.kioskea.net/faq/8619-excel-a-macro-to-automatically-insert-image-in-a-comment-box

    Sub Img_in_Commentbox()  
    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:="*.jpg", 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  
    Range("A1").AddComment  
        Range("A1").Comment.Visible = True  
    [A1].Comment.Shape.Fill.UserPicture TheFile  
    End Sub
    

提交回复
热议问题