Inserting an Online Picture to Excel with VBA

匿名 (未验证) 提交于 2019-12-03 02:31:01

问题:

I'm currently working on a project and need to fill in cells with pictures via URLs. All URLs are in one column, and I'd like to load the images in an adjacent column. I'm no VBA expert, but I found some code that worked, but for some reason I get an error (usually 5 images in) that says:

Run-time error '1004': Unable to get the Insert property of the Pictures Class

Again, I'm using a system where URLs are in one column i.e.:

xxxx.com/xxxx1.jpg

xxxx.com/xxxx2.jpg

xxxx.com/xxxx3.jpg

xxxx.com/xxxx4.jpg

Through some searching, I found that it could be linked to my Excel version (using 2010), though I'm not completely sure.

Here's the current code I'm using:

Sub URLPictureInsert() Dim cell, shp As Shape, target As Range     Set Rng = ActiveSheet.Range("a5:a50") ' range with URLs     For Each cell In Rng        filenam = cell        ActiveSheet.Pictures.Insert(filenam).Select    Set shp = Selection.ShapeRange.Item(1)    With shp       .LockAspectRatio = msoTrue       .Width = 100       .Height = 100       .Cut    End With    Cells(cell.Row, cell.Column + 1).PasteSpecial Next  End Sub

Any help would be much appreciated!

Original code source: http://www.mrexcel.com/forum/excel-questions/659968-insert-image-into-cell-url-macro.html

回答1:

This is an almost identical solution that I posted about a month ago:

Excel VBA Insert Images From Image Name in Column

Sub InsertPic() Dim pic As String 'file path of pic Dim myPicture As Picture 'embedded pic Dim rng As Range 'range over which we will iterate Dim cl As Range 'iterator  Set rng = Range("B1:B7")  '


标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!