Importing Images with URL

sfazam

New Member
Joined
Oct 26, 2014
Messages
10
Hi,

I am using following code to fetch images from URL. For bad URL macro stops working and open the message box for Debug or End. What I want is to insert a value like "Bad URL" in adjacent cell and macro should not stop until it process all URLs present in the column.

CODE:

Sub Test()
Dim url_column As Range
Dim image_column As Range

Set url_column = Worksheets(1).UsedRange.Columns("A")
Set image_column = Worksheets(1).UsedRange.Columns("B")

Dim i As Long
For i = 1 To url_column.Cells.Count

With image_column.Worksheet.Pictures.Insert(url_column.Cells(i).Value)
.Left = image_column.Cells(i).Left
.Top = image_column.Cells(i).Top
.Height = ActiveCell.Height
.Width = ActiveCell.Width
.Height = 150
.Width = 150
End With

Next
End Sub
 

Excel Facts

Test for Multiple Conditions in IF?
Use AND(test, test, test, test) or OR(test, test, test, ...) as the logical_test argument of IF.
Code tags are good. See the forum info for how to use them. Untested code with spagetti loop. Dave
Code:
Sub Test()
Dim url_column As Range
Dim image_column As Range
Dim i As Long
et url_column = Worksheets(1).UsedRange.Columns("A")
Set image_column = Worksheets(1).UsedRange.Columns("B")
For i = 1 To url_column.Cells.Count
Above:
On Error GoTo Below
With image_column.Worksheet.Pictures.Insert(url_column.Cells(i).Value)
.Left = image_column.Cells(i).Left
.Top = image_column.Cells(i).Top
.Height = ActiveCell.Height
.Width = ActiveCell.Width
.Height = 150
.Width = 150
End With
Next i

Below:
On Error GoTo 0
image_column.Cells(i + 1) = "Bad URL"
i = i + 1
GoTo Above
End Sub
 
Upvote 0
Thanks for your response.

now this code is taking time and ended with following error.

Runtime Erroor 1004


Unable to get the inset property of the image
 
Upvote 0
whoops...missed the exit sub.
Code:
Sub Test()
Dim url_column As Range
Dim image_column As Range
Dim i As Long
Set url_column = Worksheets(1).UsedRange.Columns("A")
Set image_column = Worksheets(1).UsedRange.Columns("B")
For i = 1 To url_column.Cells.Count
Above:
On Error GoTo Below
With image_column.Worksheet.Pictures.Insert(url_column.Cells(i).Value)
.Left = image_column.Cells(i).Left
.Top = image_column.Cells(i).Top
.Height = ActiveCell.Height
.Width = ActiveCell.Width
.Height = 150
.Width = 150
End With
Next i
Exit sub
Below:
On Error GoTo 0
image_column.Cells(i + 1) = "Bad URL"
i = i + 1
GoTo Above
End Sub
 
Upvote 0
Still the same error...



Unable to get the Inset property of the Picture class. When I click on Debug, it points out at following line.




Code:
With image_column.Worksheet.Pictures.Insert(url_column.Cells(i).Value)
 
Upvote 0
Well I assumed that as you mentioned, the problem was bad url's and that is why I offerred some error code to your existing code to manage it. I can't say that I follow the logic and/or the syntax of your code. Comments are also a good thing. Anyways, I assume U mean Insert not "Inset" error. Your problem is the syntax of that line of code. Stab in the dark....
Code:
With Worksheet(1).image_column.Cells(i).Pictures.Insert(url_column.Cells(i).Value)
HTH. Dave
 
Upvote 0

Forum statistics

Threads
1,214,651
Messages
6,120,742
Members
448,989
Latest member
mariah3

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