我有一张工作表,其中包含指向C3到C1002的图像的URL链接。以下代码使用这些URL链接将图像放入A3到A1002。我的问题是它只在某些时候起作用。我最近得到了“运行时错误'13”或“运行时错误'1004”。我的猜测是我的代码丢失了一块。命名范围“Image_Location”指的是范围A3到A1002。
Private Sub URL_Images_Click()
Dim URL As String 'file path of pic
Dim Pic As Picture 'embedded pic
Dim rng As Range 'range over which we will iterate
Dim Cell As Range 'iterator
Application.ScreenUpdating = False
Set rng = Range("Image_Location")
For Each Cell In rng
URL = Cell.Offset(0, 2)
If URL <> "" Then
Set Pic = ActiveSheet.Pictures.Insert(URL)
With Pic
.ShapeRange.LockAspectRatio = msoFalse
.Width = Cell.Width
.Height = Cell.Height
.Top = Rows(Cell.Row).Top
.Left = Columns(Cell.Column).Left
End With
End If
Next
Application.ScreenUpdating = True
ECT_Image_Template.Hide
End Sub