Copying Image From Network Drive to Folder on PC

buddhak

New Member
Joined
May 24, 2017
Messages
1
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.
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.
 

Excel Facts

Repeat Last Command
Pressing F4 adds dollar signs when editing a formula. When not editing, F4 repeats last command.

Forum statistics

Threads
1,223,238
Messages
6,170,939
Members
452,368
Latest member
jayp2104

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