Sub TEXT()
Dim RNG As Range, RNG1 As Range, COM As Comment, RNG2 As Range
Set RNG2 = Range("B:B")
RNG2.ClearComments
Set RNG = Range("A1", [A1].End(xlDown))
For Each RNG1 In RNG
P = "C:\Users\Administrator\Desktop\vba\Shapes\VBA基础-6.6批量在批注中插入照片_素材文件 (课程素材及源文件仅供练习学习使用,不可直接商用)\员工照片\" &RNG1.Value &".jpg"
Set COM = RNG1(1, 2).AddComment
COM.Shape.Width = 150
COM.Shape.Height = 200
COM.Shape.Fill.UserPicture P
Next
End Sub
这可不是三言两语能说的 首先你录制一个添加图片的代码 然后在那个基础上修改基本思路是 图片的名称要与你插入的地方有单元格名称进行对应 然后就容易了啊 根据单元格内容 在图片所在目录中插入对应图片即可 调整图片大小位置什么的 都可以录制宏得到代码 稍作修改即可
Sub pztp()
On Error Resume Next
Dim c As Range, P$, i&, a$, b$, arr, w!
P = "F:\唐狮图片\唐狮图片\"
For Each c In Range([c2], Cells(Rows.Count, 3).End(3))
With c
.ClearComments
.AddComment
.Comment.Shape.Fill.UserPicture P & .Value & ".jpg"
a = get_file_dim(P & .Value & ".jpg")
For i = 1 To Len(a)
If Mid(a, i, 1) Like "[0-9x]" Then
b = b & Mid(a, i, 1)
End If
Next
arr = Split(b, "x")
b = ""
w = 200 '设置图片宽度
.Comment.Shape.Width = w
.Comment.Shape.Height = Val(arr(1)) / Val(arr(0)) * w
End With
Next
End Sub
Function get_file_dim(ByVal filepath As String)
arr = [{161,162,163,164,31}]
Dim brr(), sz, i As Byte
ReDim brr(1 To UBound(arr))
Set ObiFolder = CreateObject("shell.Application").Namespace(Left(filepath, InStrRev(filepath, "\")))
For i = 1 To UBound(arr)
sz = ObiFolder.getdetailsof(ObiFolder.Items.Item(Right(filepath, Len(filepath) - InStrRev(filepath, "\"))), arr(i))
If sz Like "*[0-9] x [0-9]*" Then
get_file_dim = sz
Exit For
End If
Next i
End Function
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)