Results 1 to 1 of 1

Thread: Macro to download a document by clicking on a hyperlink in excel
Thanks Thanks: 0 Likes Likes: 0

  1. #1
    New Member
    Join Date
    Feb 2015
    Posts
    5
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default Macro to download a document by clicking on a hyperlink in excel

    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
    Last edited by rajlaim2; Feb 12th, 2019 at 05:38 PM.

Some videos you may like

User Tag List

Tags for this Thread

Like this thread? Share it with others

Like this thread? Share it with others

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •