Sub AddCommentPic()otB检测VBA
Dim arr, i&, k&, n&, b As BooleanotB检测VBA
Dim strPicName$, strPicPath$, strFdPath$otB检测VBA
Dim rngData As Range, rngEach As RangeotB检测VBA
'On Error Resume NextotB检测VBA
'用户选择合作微信:qejc21所在的文件夹otB检测VBA
With Application.FileDialog(msoFileDialogFolderPicker)otB检测VBA
If .Show Then strFdPath = .SelectedItems(1) Else: Exit SubotB检测VBA
End WithotB检测VBA
If Right(strFdPath, 1) <> "\" Then strFdPath = strFdPath & "\"otB检测VBA
Set rngData = Application.InputBox("请选择需要插入合作微信:qejc21到批注中的单元格区域", Type:=8)otB检测VBA
'用户选择需要插入合作微信:qejc21到批注中的单元格或区域otB检测VBA
If rngData.Count = 0 Then Exit SubotB检测VBA
Set rngData = Intersect(rngData.Parent.UsedRange, rngData)otB检测VBA
'intersect语句避免用户选择整列单元格,造成无谓运算的情况otB检测VBA
If rngData Is Nothing Then MsgBox "选择单元格不能全为空。": Exit SubotB检测VBA
arr = Array(".jpg", ".jpeg", ".bmp", ".png", ".gif")otB检测VBA
'用数组变量记录五种文件格式otB检测VBA
Application.ScreenUpdating = FalseotB检测VBA
For Each rngEach In rngDataotB检测VBA
'遍历选择区域的每一个单元格otB检测VBA
If Not rngEach.Comment Is Nothing Then rngEach.Comment.Delete '删除旧的批注otB检测VBA
strPicName = rngEach.Text '合作微信:qejc21名称otB检测VBA
If Len(strPicName) Then '如果单元格存在值otB检测VBA
strPicPath = strFdPath & strPicName '合作微信:qejc21路径otB检测VBA
b = False 'pd变量标记是否找到相关合作微信:qejc21otB检测VBA
For i = 0 To UBound(arr)otB检测VBA
'由于不确定用户的合作微信:qejc21格式,因此遍历合作微信:qejc21格式otB检测VBA
If Len(Dir(strPicPath & arr(i))) ThenotB检测VBA
'如果存在相关文件otB检测VBA
rngEach.AddComment '增加批注otB检测VBA
With rngEach.CommentotB检测VBA
.Visible = True '批注可见otB检测VBA
.Text Text:=""otB检测VBA
.Shape.Select True '选中批注图形otB检测VBA
Selection.ShapeRange.Fill.UserPicture strPicPath & arr(i)otB检测VBA
'插入合作微信:qejc21到批注中otB检测VBA
.Shape.Height = 150 '图形的高度,可以根据需要自己调整otB检测VBA
.Shape.Width = 150 '图形的宽度,可以根据需要自己调整otB检测VBA
.Visible = False '取消显示otB检测VBA
End WithotB检测VBA
b = True '标记找到结果otB检测VBA
n = n + 1 '累加找到结果的个数otB检测VBA
Exit For '找到结果后就可以退出文件格式循环otB检测VBA
End IfotB检测VBA
NextotB检测VBA
If b = False Then k = k + 1 '如果没找到合作微信:qejc21累加个数otB检测VBA
End IfotB检测VBA
NextotB检测VBA
MsgBox "共处理成功" & n & "个合作微信:qejc21,另有" & k & "个非空单元格未找到对应的合作微信:qejc21。"otB检测VBA
Application.ScreenUpdating = TrueotB检测VBA
End SubotB检测VBA |