SOLVED

How to display image in excel from given url?

Copper Contributor

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:

Screenshot (49).png

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

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

@NikolinoDE  Thanks for reply. I use the same reference but this is not working in my Scenario.

@Nishchal_Vashisht 

Just in case, IMAGE(url, alt_text,...) function appeared in Beta version. Have no idea how much time it takes to see it in production.

best response confirmed by Nishchal_Vashisht (Copper Contributor)
Solution

@NikolinoDE It didn't work for me. I am downloading my Excel File from Salesforce and I have made changes in column ranges accordingly but didn't work. I am not sure whether it is because of Spreadsheet format I am downloading from salesforce or anything else. I am attaching my File here 
Could you please help me with it.
https://mega.nz/file/Eqx1zZDI#hmrJduhQ77zReZi2fFxRM2aaSwaUGVPLbhQc-FBavcg 

 

@Nishchal_Vashisht 

The file cannot be opened and if I open it anyway, it is empty.

If you cannot insert the file, then send the file as a private message.
I don't know your digital environment, so I can't make any statements as to why it's not working for you.

 

Here is another VBA code, maybe it works for you.

At least if not, it will "Debug" and show you the error line.

 

At the same time, if I may recommend, additional information about Excel version, operating system and storage medium would be beneficial for all participants, most of all for you.

 

Thank you for your understanding and patience

@NikolinoDE After downloading the file please click enable editing after that you will it's data
1 best response

Accepted Solutions
best response confirmed by Nishchal_Vashisht (Copper Contributor)