VBA URL to image (debug error)

mickyflash

Board Regular
Joined
Jan 29, 2009
Messages
77
H Guys - I have this code that deletes any images on the worksheet and then takes the url address in A2 and displays the image from the address 4 columns to the left.

Code:
Public Sub Add_Images_To_Cells()


ActiveSheet.Pictures.DELETE


    Dim lastRow As Long
    Dim URLs As Range, URL As Range
    
    With ActiveSheet
        lastRow = .Cells(Rows.Count, "A").End(xlUp).Row
        Set URLs = .Range("A2:A" & lastRow)
    End With


    For Each URL In URLs
        URL.Offset(0, 4).Select
        URL.Parent.Pictures.Insert URL.Value
        DoEvents
    Next
    
End Sub


This working (almost) in so much as the image is getting displayed, but I keep getting a debug error relating to the

Code:
URL.Parent.Pictures.Insert URL.Value line.

Can anyone see why Im having this error come up? Thanks in advance
 
Last edited:

Excel Facts

What is the shortcut key for Format Selection?
Ctrl+1 (the number one) will open the Format dialog for whatever is selected.
When the error occurs at that line, what is the value of URL.Value? Is it a valid path and filename? (Note: You can move your cursor over URL.Value to display the value.)
 
Last edited:
Upvote 0
When the error occurs at that line, what is the value of URL.Value? Is it a valid path and filename? (Note: You can move your cursor over URL.Value to display the value.)


The URL.Value has a value but its not a path it seems to ="GK" (If the player selected is a Goalkeeper) ="CB" (if player is Centre Back)
 
Upvote 0
Thanks for the advice I changed this line:
Code:
[COLOR=#333333]Set URLs = .Range("A2:A" & lastRow)[/COLOR]
to
Code:
[COLOR=#333333]Set URLs = .Range("A2")[/COLOR]

and it seems to be working now
 
Upvote 0
yes there is a valid URL in cell A2

While A2 contains a valid URL, it's likely that one or more cells in Column A do not, hence the error.

Thanks for the advice I changed this line:
Rich (BB code):
Set URLs = .Range("A2:A" & lastRow)
to
Rich (BB code):
Set URLs = .Range("A2")
and it seems to be working now

Yes, but isn't the intent to loop through each cell in Column A, instead of only A2 ?
 
Upvote 0

Forum statistics

Threads
1,223,893
Messages
6,175,240
Members
452,621
Latest member
Laura_PinksBTHFT

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