因为如下代码有EXCEL文件没有对应的相片,所以出现错误。VBA忽略错误的代码是什么啊?
Sub Macro1()
mypath = ThisWorkbook.Path & "\"
wj = Dir(mypath & "*.xls")
Application.ScreenUpdating = False
Do While wj <> ""
If wj <> ThisWorkbook.Name Then
With Workbooks.Open(mypath & wj)
ActiveSheet.DrawingObjects.Delete
x = [i3:i7].Left: y = [i3:i7].Top
w = [i3:i7].Width: h = [i3:i7].Height
ActiveSheet.Shapes.AddShape(msoShapeRectangle, x, y, w, h).Select
Selection.ShapeRange.Fill.UserPicture mypath & "\" & Split(wj, ".xls")(0) & ".jpg"
.Close True
End With
End If
wj = Dir
Loop
MsgBox "插入图片完毕"
Application.ScreenUpdating = True
End Sub