Hi everyone. I have a document that I have links which open up a PDF and I would like a macro to go through and download all of these documents into a file path. Is this possible? Thank you for your help.
I have this vba as of now which downloads the pdf but nothing appears in the PDF I think its because a warning box comes up when I click on the hyperlink so I think I need the macro to be able to also click on to the warning?
Sub Test()
Dim FileNum As Long
Dim FileData() As Byte
Dim MyFile As String
Dim WHTTP As Object
On Error Resume Next
Set WHTTP = CreateObject("WinHTTP.WinHTTPrequest.5")
If Err.Number <> 0 Then
Set WHTTP = CreateObject("WinHTTP.WinHTTPrequest.5.1")
End If
On Error GoTo 0
MyFile = "https://ABC.pdf"
WHTTP.Open "GET", MyFile, False
WHTTP.Send
FileData = WHTTP.ResponseBody
Set WHTTP = Nothing
If Dir("C:\MyDownloads", vbDirectory) = Empty Then MkDir "C:\MyDownloads"
FileNum = FreeFile
Open "C:\MyDownloads\Test.pdf" For Binary Access Write As #FileNum
Put #FileNum , 1, FileData
Close #FileNum
End Sub
I have this vba as of now which downloads the pdf but nothing appears in the PDF I think its because a warning box comes up when I click on the hyperlink so I think I need the macro to be able to also click on to the warning?
Sub Test()
Dim FileNum As Long
Dim FileData() As Byte
Dim MyFile As String
Dim WHTTP As Object
On Error Resume Next
Set WHTTP = CreateObject("WinHTTP.WinHTTPrequest.5")
If Err.Number <> 0 Then
Set WHTTP = CreateObject("WinHTTP.WinHTTPrequest.5.1")
End If
On Error GoTo 0
MyFile = "https://ABC.pdf"
WHTTP.Open "GET", MyFile, False
WHTTP.Send
FileData = WHTTP.ResponseBody
Set WHTTP = Nothing
If Dir("C:\MyDownloads", vbDirectory) = Empty Then MkDir "C:\MyDownloads"
FileNum = FreeFile
Open "C:\MyDownloads\Test.pdf" For Binary Access Write As #FileNum
Put #FileNum , 1, FileData
Close #FileNum
End Sub
Last edited: