add image as comment VBA

前端 未结 6 1290
小蘑菇
小蘑菇 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:29

    I updated code above and also I take path to the image from Column "B" (Column 2). I raun my macro on cell click:

    Private Sub Worksheet_SelectionChange(ByVal Target As Range)
    Dim listWS As Worksheet
    Dim targetCol, targetRow As Long
    Dim TheFile As String
    
    Set listWS = Application.ThisWorkbook.Sheets("Catalogue")
        If Target.Column = 2 Then
            targetCol = Target.Column
            targetRow = Target.Row
            TheFile = listWS.Cells(targetRow, targetCol).Value
            With listWS.Range(listWS.Cells(targetRow, 4), listWS.Cells(targetRow, 4))
                .AddComment
                .Comment.Visible = True
                .Comment.Shape.Fill.UserPicture TheFile
            End With
        End If
    End Sub
    

提交回复
热议问题