insert image URL images into CELLS

excel_2009

Active Member
Joined
Sep 14, 2009
Messages
318
hi excel gurus,

I was wondering if it would be possible to insert image urls as images into cells in excel? if so how?

thank you
 
Hi Andrew,

That is perfect, however can i adjust the coding so that there is a range? but the range of rows will vary on any given day but the image url will always be in the same column?

i hope that makes sense?

:)
 
Upvote 0

Excel Facts

When did Power Query debut in Excel?
Although it was an add-in in Excel 2010 & Excel 2013, Power Query became a part of Excel in 2016, in Data, Get & Transform Data.
Yes, of course:

Code:
Sub Test()
    Dim Rng As Range
    Dim Cell As Range
    Dim Pic As Picture
    Application.ScreenUpdating = False
    Set Rng = Range("C1:C" & Range("c" & Rows.Count).End(xlUp).Row)
    For Each Cell In Rng
        With Cell
            Set Pic = .Parent.Pictures.Insert(.Value)
            With .Offset(, -1)
                Pic.Top = .Top
                Pic.Left = .Left
                Pic.Height = .Height
                Pic.Width = .Width
            End With
        End With
    Next Cell
    Application.ScreenUpdating = True
End Sub
 
Upvote 0
Hi Andrew,

I've just executed the coding however I get the following error :

Run-time error 1004

Unable to get the Insert property of the Pictures class

and it highlights this line when i debug:

Set Pic = .Parent.Pictures.Insert(.Value)

:confused:
 
Upvote 0
Oddly enough,

I restarted my P.C and now its working fine?! :biggrin:

Very strange, THank you Andrew you have been extremely helpful :)
 
Upvote 0
Hi Andrew,

I have one last question regarding this topic, some image urls are broken thereby causing the runtime error, is it possible to ignore those errors?

i've adapated the coding to the following:
Code:
 Sub IMAGE()
   

On Error Resume Next


  Dim Rng As Range
    Dim Cell As Range
    Dim Pic As Picture
    
    Application.ScreenUpdating = False
    Columns("J:J").ColumnWidth = 21.29
    
    Set Rng = Range("K2:K" & Range("k" & Rows.Count).End(xlUp).Row)
    For Each Cell In Rng
        With Cell
            Set Pic = .Parent.Pictures.Insert(.Value)
            With .Offset(, -1)
                Pic.Top = .Top
                Pic.Left = .Left
                Pic.Height = .Height
                Pic.Width = .Width
            End With
        End With
    Next Cell
    
    On Error GoTo 0
    
    Rows("2:11").RowHeight = 120
    Application.ScreenUpdating = True




End Sub

However if there is a broken URL in cell K8 then the image of cell K7 shows in its place in J8 which is really bizarre?? any idea on how this could be fixed? :confused:

Thank you
 
Upvote 0
Maybe try:

Code:
Sub IMAGE()
    Dim Rng As Range
    Dim Cell As Range
    Dim Pic As Picture
    Application.ScreenUpdating = False
    Columns("J:J").ColumnWidth = 21.29
    Set Rng = Range("K2:K" & Range("k" & Rows.Count).End(xlUp).Row)
    For Each Cell In Rng
        With Cell
            On Error Resume Next
            Set Pic = .Parent.Pictures.Insert(.Value)
            If Err <> 0 Then
                Err.Clear
            Else
                With .Offset(, -1)
                    Pic.Top = .Top
                    Pic.Left = .Left
                    Pic.Height = .Height
                    Pic.Width = .Width
                End With
            End If
            On Error GoTo 0
        End With
    Next Cell
    Rows("2:11").RowHeight = 120
    Application.ScreenUpdating = True
End Sub
 
Upvote 0
Hi Andrew,

That is the definition of perfect!!! you have been extremely helpful, you truly are an asset to the excel community :)

On the offchance, do you know how to adapt this line so that its flexible:

Code:
Rows("2:30").RowHeight = 120

i.e the number of rows on any given day changes, there might be 10 rows, 100, 1000 etc

Is that possible?

Thank you so much!!!!!!!!!!!
 
Upvote 0

Forum statistics

Threads
1,223,373
Messages
6,171,693
Members
452,418
Latest member
kennettz

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top