|
[广告] VBA代码宝 - VBA编程加强工具 · VBA代码随查随用 · 内置多项VBA编程加强工具 ★ 免费下载 ★ ★ 使用手册★
代码如下。。
Sub test()
maxR = Sheet1.[c1048576].End(3).Row
If maxR <= 2 Then MsgBox "工作表空!!!": Exit Sub
With Application.FileDialog(msoFileDialogFolderPicker)
.AllowMultiSelect = False
.InitialFileName = ThisWorkbook.Path & "\"
.Title = "选择文件夹:"
If .Show = -1 Then p = .SelectedItems(1) Else MsgBox "没有选择文件夹!退出!": Exit Sub
End With
Set Rng = Sheet1.Range("c3:c" & maxR)
For Each rng1 In Rng
f = p & "\" & rng1.Value & ".jpg"
f_exist = Dir(f)
If f_exist <> "" Then
For Each shp In Sheet1.Pictures '先删除原有的图片,否则测试叠了一堆图片
If Round(shp.Top, 2) = Round(rng1.Offset(, -1).Top, 2) Then
shp.Delete
End If
Next
Set shp = Sheet1.Shapes.AddPicture(f, False, True, rng1.Offset(, -1).Left, _
rng1.Offset(, -1).Top, rng1.Offset(, -1).Width, rng1.Offset(, -1).Height)
shp.Placement = xlMoveAndSize '自适应大小
shp.LockAspectRatio = msoFalse '取消锁定纵横比
Else
MsgBox f & "不存在!!"
End If
Next
Beep
End Sub
|
|