单个插入的常规方法
如果在Excel某单元格插入图片批注,其详细步骤如下:
1.右键某个单元格,然后选择“新建注释”;
2.在注释边框上,右键选择“设置批注格式”;
3.在“设置批注格式”对话框中,依次选择“颜色与线条”--->“填充”--->“填充效果”;
4.在“填充效果”对话框里,点击“图片”--->“选择图片”。
批量插入的VBA代码
如果要在多个单元格插入图片批注,一个一个单元格重复以上操作,显然不是较好的选择。要实现批量插入图片批注,我们可以利用VBA。
Sub 批量插入图片批注()
Dim Cmt As Comment
On Error Resume Next
Dim MR As Range
Dim Pics As String
For Each MR In Selection
If Not IsEmpty(MR) Then
MR.Select
MR.AddComment
MR.Comment.Visible = False
MR.Comment.Text Text:=""
MR.Comment.Shape.Fill.UserPicture PictureFile:= _
"C:\Users\VBAMatrix\Documents\IMGTest\" & MR.Value & ".jpg"
End If
Next
'修改图片注释的长宽
For Each Cmt In ActiveSheet.Comments
Cmt.Parent.Comment.Shape.Width = 200
Cmt.Parent.Comment.Shape.Height = 100
Next
End Sub
