add image as comment VBA

前端 未结 6 1295
小蘑菇
小蘑菇 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 can be used for batch operations add a bunch of images as comment in one go

    Sub Fill_Selection_with_Image_As_Comments()
    
    Dim n As Integer
    Dim i As Integer
    Dim cmt As Comment
    Dim rng As Range
    Dim Workrng As Range
    Dim strPic As String
    
    On Error Resume Next
    
    Set Workrng = Application.Selection
    Set Workrng = Application.InputBox(Prompt:="Please select a range!", Title:="Range to target", Type:=8)
    i = 1
    
    With Application.FileDialog(msoFileDialogFilePicker)
        .AllowMultiSelect = True
        .Title = "Select Images"
        .ButtonName = "Select"
        If .Show <> -1 Then
            Exit Sub
        End If
    
        n = .SelectedItems.Count
    
        For Each rng In Workrng
            rng.AddComment
            Set cmt = rng.Comment
           If Not cmt Is Nothing Then
            strPic = .SelectedItems(i)
                With cmt.Shape
                    .Height = 400
                    .Width = 500
                    .Fill.UserPicture strPic
    
                End With
           End If
            i = i + 1
            If i = n + 1 Then
                Exit Sub
            End If
       Next rng
    End With
    
    MsgBox "Done"
    End Sub
    

    Hope this helps some one who is finding a batch operations work.

提交回复
热议问题