krishna008
New Member
- Joined
- Jan 7, 2010
- Messages
- 12
I got the url for each jpeg for an inline flip book . There are 300 jpegs meaning 300 urls. I will add them to column A of an excel sheet. Im new to vba could anyone help me with this vba code to open each URL from column A and download the jpeg file
Sub DownloadJPEGS()
Dim ws As Worksheet
Dim lastRow As Long
Dim i As Long
Dim url As String, savePath As String
Set ws = ThisWorkbook.Sheets("Sheet1") ' Change "Sheet1" to your sheet name
lastRow = ws.Cells(ws.Rows.Count, "A").End(xlUp).Row
For i = 1 To lastRow
url = ws.Cells(i, 1).Value
savePath = "C:\Your\Desired\Save\Path\File" & i & ".jpg" ' Change the save path accordingly
With CreateObject("MSXML2.ServerXMLHTTP")
.Open "GET", url, False
.send
If .Status = 200 Then
Open savePath For Binary Access Write As #1
Put #1, , .responseBody
Close #1
Debug.Print "File " & i & " downloaded successfully."
Else
Debug.Print "Error downloading file " & i & "."
End If
End With
Next i
End Sub
Sub DownloadJPEGS()
Dim ws As Worksheet
Dim lastRow As Long
Dim i As Long
Dim url As String, savePath As String
Set ws = ThisWorkbook.Sheets("Sheet1") ' Change "Sheet1" to your sheet name
lastRow = ws.Cells(ws.Rows.Count, "A").End(xlUp).Row
For i = 1 To lastRow
url = ws.Cells(i, 1).Value
savePath = "C:\Your\Desired\Save\Path\File" & i & ".jpg" ' Change the save path accordingly
With CreateObject("MSXML2.ServerXMLHTTP")
.Open "GET", url, False
.send
If .Status = 200 Then
Open savePath For Binary Access Write As #1
Put #1, , .responseBody
Close #1
Debug.Print "File " & i & " downloaded successfully."
Else
Debug.Print "Error downloading file " & i & "."
End If
End With
Next i
End Sub