I am trying to create a macro that will download an image based on multiple file paths to folders on a network drive and rename them based on the text information in column A with the paths being in column B. I already have a macro that does exactly what I need for the http hyperlinks in column C which is listed below.
My spread sheet is set up as such
column A - column B - column C
21561 - N:\pathtoimage.jpg - http://pathtofile.pdf
45456 - N:\pathtoimage.jpg - http://pathtofile.pdf
So just to recap, Macro needs to download the image from column B rename it with the corresponding data in column A and save it to a folder on the Users Desktop.
Code:
Const TargetFolder = "C:\Users\rykenes\Desktop\Output\"Private Declare PtrSafe 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 Test()
For Each Hyperlink In ActiveSheet.Hyperlinks
LocalFileName = ActiveSheet.Cells(Hyperlink.Range.Row, 1).Value & ".pdf"
Call HTTPDownloadFile(Hyperlink.Address, TargetFolder & LocalFileName)
Next Hyperlink
End Sub
Sub HTTPDownloadFile(ByVal URL As String, ByVal LocalFileName As String)
Dim Res As Long
On Error Resume Next
Kill LocalFileName
On Error GoTo 0
Res = URLDownloadToFile(0&, URL, LocalFileName, 0&, 0&)
End Sub
My spread sheet is set up as such
column A - column B - column C
21561 - N:\pathtoimage.jpg - http://pathtofile.pdf
45456 - N:\pathtoimage.jpg - http://pathtofile.pdf
So just to recap, Macro needs to download the image from column B rename it with the corresponding data in column A and save it to a folder on the Users Desktop.