|
楼主 |
发表于 2023-6-8 19:26
|
显示全部楼层
[广告] VBA代码宝 - VBA编程加强工具 · VBA代码随查随用 · 内置多项VBA编程加强工具 ★ 免费下载 ★ ★ 使用手册★
Private Sub CommandButton1_Click() '插入图片需要选文件夹
Set fd = Application.FileDialog(msoFileDialogFolderPicker)
If fd.Show = -1 Then
t = fd.SelectedItems(1)
Else
MsgBox "未选择文件夹,程序结束”"
Exit Sub
End If
Dim ss As Range, sp As Shape
For Each sp In ActiveSheet.Shapes
If sp.Type <> 12 Then
sp.Delete
End If
Next sp
For Each ss In Range("a2", Cells(Rows.Count, 1).End(xlUp))
For Each kk In [{"bpm","png","gif","jpeg"}]
dz = t & "\" & ss.Value & "." & kk
If Dir(dz, 16) <> Empty Then ''判断有没有这个文件
Z = ss.Offset(0, 1).Left
d = ss.Offset(0, 1).Top
k = ss.Offset(0, 1).Width
g = ss.Offset(0, 1).Height
ActiveSheet.Shapes.AddPicture dz, 1, 1, Z, d, k, g
End If
Next
Next ss
End Sub
这样只选择PNG格式的了,还是不行 |
|