URL/HYPERLINK

S

samboy

I have urls/hyperlinks in a column of my spreadsheet linking to my suppliers
image server? how do I retrieve the iamges and save the image in a file and
place the jpeg/gif name in an adjacent cell. there are approximatly 15000
url. Can it be automated.
 
C

Chip Pearson

The following code should get you started in the right direction. It
will download the file that is the target of the hyperlink in A1 to
the folder named in FolderName.


Private Declare Function URLDownloadToFile _
Lib "urlmon" Alias "URLDownloadToFileA" ( _
ByVal pCaller As Long, _
ByVal szURL As String, _
ByVal szFileName As String, _
ByVal dwReserved As Long, _
ByVal lpfnCB As Long) As Long

Sub AAA()
Dim FolderName As String
Dim URL As String
Dim FName As String

FolderName = "C:\Test" '<<< CHANGE
URL = Range("A1").Hyperlinks(1).Address '<<< CHANGE
FName = FolderName & "\" & Mid(URL, InStrRev(URL, "/") + 1)
URLDownloadToFile 0&, URL, FName, 0&, 0&
End Sub

Cordially,
Chip Pearson
Microsoft Most Valuable Professional
Excel Product Group, 1998 - 2009
Pearson Software Consulting, LLC
www.cpearson.com
(email on web site)
 
S

samboy

If I got this correct you want to place the target file to receive the image
between the quote marks at (FolderName = "C:\Test" '<<< CHANGE) and the
hyperlink range D2:D15000

Anything else in the equation I need to add?


Thanks for the tip, that helps greatly.
 
S

samboy

This is how I modified what you gave me, it worked to download the image from
hyperlink in "D2" but none of the others. I am not sure why, I specified the
range thru D12. Any further clue. I am excited it did the one. THANKS!

Below is how modified the macro.


Private Declare Function URLDownloadToFile _
Lib "urlmon" Alias "URLDownloadToFileA" ( _
ByVal pCaller As Long, _
ByVal szURL As String, _
ByVal szFileName As String, _
ByVal dwReserved As Long, _
ByVal lpfnCB As Long) As Long

Sub AAA()
Dim FolderName As String
Dim URL As String
Dim FName As String

FolderName = "C:\Test" '<<< CHANGE
URL = Range("D2:D12").Hyperlinks(1).Address '<<< CHANGE
FName = FolderName & "\" & Mid(URL, InStrRev(URL, "/") + 1)
URLDownloadToFile 0&, URL, FName, 0&, 0&
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top