代码如下:
Sub InsertPic()
"ExcelHome VBA编程学习与实践 by:看见星光
Dim Arr, i&, k&, n&, pd&
Dim PicName$, PicPath$, FdPath$, shp As Shape
Dim Rng As Range, Cll As Range, Rg As Range, book$
"On Error Resume Next
"用户选择图片所在的文件夹
With Application.FileDialog(msoFileDialogFolderPicker)
.AllowMultiSelect = False "不允许多选
If .Show Then FdPath = .SelectedItems(1) Else: Exit Sub
End With
If Right(FdPath, 1) <> "\" Then FdPath = FdPath & "\"
Set Rng = Application.InputBox("请选择图片名称所在的单元格区域", Type:=8)
"用户选择需要插入图片的名称所在单元格范围
Set Rng = Intersect(Rng.Parent.UsedRan