Downloading Image from URL and Linking to a Local Copy in Workbook

SerenityNetworks

Board Regular
Joined
Aug 13, 2009
Messages
131
Office Version
  1. 365
Platform
  1. Windows
I was using the code below to display in Column-B the image located at the URL in Column-A. I'll loop through the code to display in the worksheet thousands of images. The initial download will always take time, but just reopening the workbook at a later time is dismally slow when the images are located on the web.

I am not a coder, although I can tweak code once given an example. Would there be a way to modify the code below so that either:
  1. The macro downloads the image file to a local directory (a named sub-directory where the Excel file is located) and then place the link path in one column and display the image in the next column? (So Column-A would contain the initial URL to the image file. Column-B would contain the path (URL) to the local file of the image. Column-C would display the image stored locally.
  2. Modify the code to simply place the actual image into the Excel file. (The images are 80 to 150k in size, so I'd just limit the number of URLs to keep the Excel file from becoming too large.)

Option 1 would be really nice, but if it isn't easily doable then Option 2 would work for me as well.

Thank you in advance,
Andrew

Code:
Sub Test()
    Dim Pic As Picture
    Application.ScreenUpdating = False
    With ActiveSheet.Range("A1")
        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
    Application.ScreenUpdating = True
End Sub
 
Last edited:

Excel Facts

How to total the visible cells?
From the first blank cell below a filtered data set, press Alt+=. Instead of SUM, you will get SUBTOTAL(9,)
UPDATE:

I have found some examples that I can use to tweak for Option 1. I'm trying them now. I will post back with any questions or results.

Thank you,
Andrew
 
Upvote 0
I'm stuck with an error I've not encountered before. The macro (below) runs and displays the images I've downloaded to a local directory. Then at the end of the macro I receive the "Code execution has been interrupted" error. I press "Continue" and the macro ends. I'm not sure what I've done or not finished that I'm receiving this error.

Any help will be appreciated.

Thanks,
Andrew

Code:
Sub DisplayImage()
    Dim pic As Picture
    Dim lastRow As Long
    Dim myRow As Long
    Application.ScreenUpdating = False
'   Find last row in column N
    lastRow = Cells(Rows.Count, "N").End(xlUp).Row
'   Loop through column L
    For myRow = 5 To lastRow
        With ActiveSheet.Range("L" & myRow)
            Set pic = .Parent.Pictures.Insert("C:\test\" & .Value)
            With .Offset(, 3)
                pic.Top = .Top + 1
                pic.Left = .Left + 1
                pic.Height = .Height - 1
                pic.Width = .Width - 1
                pic.Placement = xlMoveAndSize
                pic.ShapeRange.LockAspectRatio = msoTrue
            End With
        End With
    Next myRow
    Application.ScreenUpdating = True
    MsgBox "Done"
End Sub
 
Upvote 0

Forum statistics

Threads
1,223,234
Messages
6,170,891
Members
452,366
Latest member
TePunaBloke

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