Sub 批量插入同名照片到批注()
Dim a
a = MsgBox("【特别注意】:选中图片文件夹,保证图片文件名与插入批注表格的内容一样!", vbOKCancel, "【蓝迪资料员HM】")
Dim cell As Range, fd, t
Dim PicPath As String
Dim ErrCell As String
Selection.ClearComments
On Error Resume Next
Set fd = Application.FileDialog(msoFileDialogFolderPicker) '允许用户选择一个文件夹
If fd.Show = -1 Then
t = fd.SelectedItems(1) '选择之后就记录这个文件夹名称
End If
For Each cell In Selection
If Dir(t & "\" & cell.Text & ".jpg", 16) <> Empty Then
With cell.AddComment
.Visible = True
.Text Text:="cccc"
.Shape.Select True
Selection.ShapeRange.Fill.UserPicture t & "\" & cell.Text & ".jpg"
.Shape.Width = 150 'Add these 2 statement
.Shape.Height = 150
.Visible = False
End With
End If
cell.Offset(1, 0).Select
Next
End Sub
判断一下,没有图片就不执行插入批注的代码