Tried to make a macro that progressively inserts 3 images in Excel
试图制作一个宏,逐步在Excel中插入3个图像
One worksheet (pics) contains the URLs of images in Column A row 1-3
一个工作表(图片)包含A列第1-3行中图像的URL
The other worksheet (outputs) is supposed to output the images horizontally.
其他工作表(输出)应该水平输出图像。
Sub testinsertpix()
Dim i As Integer
Dim link As String
For i = 1 To 3
link = Worksheets("pics").Cells(i, "A").Value
Cells(1, i).Select
ActiveSheet.Pictures.Insert (link)
Next i
End Sub
It does insert the first image, but fails when the loop reaches the 2nd picture.
它会插入第一张图像,但在循环到达第二张图片时失败。
"Insert method of Pictures class failed"
“插入图片类的方法失败”
Little help please?
请帮忙吗?
2 个解决方案
#1
0
Try:
尝试:
Dim link as Variant
Then output the value and see where it's going wrong. My best guess is your URL isn't being read the way you'd expect.
然后输出值并查看它出错的地方。我最好的猜测是你的网址没有按照你期望的方式阅读。
#2
0
I have a similar macro and I had the same error. For me this helped: On error resume next
我有一个类似的宏,我有同样的错误。对我来说这有帮助:接下来错误恢复
Sub INSERTPICTURES()
With Sheets("Condition_report")
Dim cella As Range
For Each cella In .Range("A1:A10000").Cells
If cella.Interior.ColorIndex = 3 Then
ActiveSheet.Shapes.AddPicture Filename:=cella, LinkToFile:=msoFalse, SaveWithDocument:=msoCTrue, Left:=cella.MergeArea.Left, Top:=cella.MergeArea.Top, Width:=cella.MergeArea.Width - 3, Height:=cella.MergeArea.Height
On Error Resume Next
End If
Next
End With
End Sub
#1
0
Try:
尝试:
Dim link as Variant
Then output the value and see where it's going wrong. My best guess is your URL isn't being read the way you'd expect.
然后输出值并查看它出错的地方。我最好的猜测是你的网址没有按照你期望的方式阅读。
#2
0
I have a similar macro and I had the same error. For me this helped: On error resume next
我有一个类似的宏,我有同样的错误。对我来说这有帮助:接下来错误恢复
Sub INSERTPICTURES()
With Sheets("Condition_report")
Dim cella As Range
For Each cella In .Range("A1:A10000").Cells
If cella.Interior.ColorIndex = 3 Then
ActiveSheet.Shapes.AddPicture Filename:=cella, LinkToFile:=msoFalse, SaveWithDocument:=msoCTrue, Left:=cella.MergeArea.Left, Top:=cella.MergeArea.Top, Width:=cella.MergeArea.Width - 3, Height:=cella.MergeArea.Height
On Error Resume Next
End If
Next
End With
End Sub