I have a file with:
column A = name
column B = URL (ending in "pdf" or "jpg")
column C = extension from column B so either ".pdf" or ".jpg"
For each URL, the macro downloads the file and renames it with the values of column A + column B. However, the problem is that I want the files to be placed into a folder that has the same name as column A (these folders already exist). I can't figure out how to correct the file location listed below as "F:\test\folderpath" within the URLDownloadToFile function. In other words, it's easy to get the files to all download into a folder, but I want each to go into the custom folder I've built for each value in column A. I realize my use of "folderpath" in the location path is wrong so need help there. Any help is greatly appreciated. Thanks!
Option Explicit
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
Dim Ret As Long
Sub Sample()
Dim ws As Worksheet
Dim LastRow As Long, i As Long
Dim strPath As String
Dim folderpath As String
Set ws = Sheets("form-data")
LastRow = ws.Range("A" & Rows.Count).End(xlUp).Row
For i = 2 To LastRow '
strPath = ws.Range("A" & i).Value & ws.Range("C" & i).Value
folderpath = ws.Range("A" & i).Value
Ret = URLDownloadToFile(0, ws.Range("B" & i).Value, "F:\test\folderpath" & strPath, 0, 0)
Next i
End Sub
Bookmarks