Forum Discussion

Nishchal_Vashisht's avatar
Nishchal_Vashisht
Copper Contributor
Sep 03, 2022
Solved

How to display image in excel from given url?

I downloaded a file which include a column of image URL. I want to convert these URL into actual images for that I have Written a VB code but I don't know why it is throwing me following error : Run time error 1004 Unable to get the Insert property of pictures class

My Excel file looks like:

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

while My VB Code is

 

Public Sub Add_Images_To_Cells()

Dim lastRow As Long
Dim URLs As Range, URL As Range
Dim pic As Picture
Dim urlColumn As String

With ActiveSheet
    urlColumn = "F"
    lastRow = .Cells(Rows.Count, urlColumn).End(xlUp).Row
    Set URLs = .Range(urlColumn & "3:" & urlColumn & lastRow)
End With

For Each URL In URLs
    If InStr(URL.Value, "http") > 0 Then
        URL.Offset(0, 0).Select
        Set pic = URL.Parent.Pictures.Insert(URL.Value)
        With pic.ShapeRange
            .LockAspectRatio = msoFalse
            .Height = URL.Offset(0, 0).Height - 1
            .Width = URL.Offset(0, 0).Width - 1
            .LockAspectRatio = msoTrue
        End With
        
        URL.Clear
        DoEvents
    End If
Next
End Sub

On Debugging the debugger is highlighting this line Set pic =URL.Parent.Pictures.Insert(URL.Value)

Can anyone help how I display images instead of URL either in the same column or other column?

7 Replies

Resources