|
以下在我用在个人宏工作薄和加载宏的代码,不知道什么原因不能批量导入图片,但如果放在要导入图片的工作表来执行,可以执行成功;
Sub 导入图片()
Dim i
Dim Rng As Range, R As Range
Dim P As String, F As String, S As String
Dim PIC As Object
On Error Resume Next
bk = ActiveWorkbook.Name
Set objFD = Application.FileDialog(msoFileDialogFolderPicker)
With objFD
If .Show = -1 Then
' 如果单击了确定按钮,则将选取的路径保存在变量中
sPath = .SelectedItems(1)
End If
End With
P = sPath & "\"
Application.ScreenUpdating = False
Workbooks(bk).Activate
Set Rng = Selection
For Each R In Rng
F = R.Text & ".PNG"
S = R.Address
If Dir(P & F) <> "" Then
Set R = R.Offset(0, 1)
Shapes.AddPicture(P & F, True, True, R.Left + 7, R.Top + 1, R.Width * 0.8, R.Height).Name = S
ActiveSheet.Shapes.Range(Array(S)).Select
Selection.ShapeRange.ZOrder msoSendToBack
End If
Next
Application.ScreenUpdating = True
End Sub
|
|