We help IT Professionals succeed at work.

PDf download using VBA

Sandesh555
Sandesh555 asked
on
Hi Team,

I am doing  one Web automation project using VBA(EXCEL) , in this project i want 2 download PDF file....how can i download pdf file without any display alerts (like save as window)
Comment
Watch Question

May be you can give it a shot with SendKeys

Something like this....


    Application.CommandBars("Web").Visible = True
    ActiveWorkbook.FollowHyperlink Address:= _
        "http://Download_Link.com/", NewWindow:=False, AddHistory:= _
        True
    SendKeys Filename & "{ENTER}", False
Sample code from the archives...

[ http://www.experts-exchange.com/Applications/MS_Office/Excel/Q_21424559.html ]

See my comment "16/05/05 02:26 PM, ID: 14010027".

Use the syntax:

If (blnDownload_File("http:\\website\folder\filename.pdf", "c:\LocalDocuments\downloaded.pdf")) Then
    ' Success
Else
    ' Failure
End If

BFN,

fp.
<Hi Nigel :) >

You can also use the Matty Vidas approach of XMLHTTP

The code below downloads a file from
http://mailchimp.com/downloads/ExpertsExchangeProgram.pdf
to  the location
"C:/test/temp.pdf"

Drawing heavily on these two posts

http://www.vbaexpress.com/kb/getarticle.php?kb_id=799
http://stackoverflow.com/questions/204759/http-get-in-vbs

Cheers

Dave
Sub PDF_Download()
    Dim oXMLHTTP As Object
    Dim oStream As Object
    Dim strUrl As String
    Dim strFilePath As String

    strFilePath = "C:/test/temp.pdf"
    strUrl = "http://mailchimp.com/downloads/ExpertsExchangeProgram.pdf"
    Set oXMLHTTP = CreateObject("MSXML2.XMLHTTP.3.0")

    oXMLHTTP.Open "GET", strUrl, False
    oXMLHTTP.Send

    If oXMLHTTP.Status = 200 Then
    If Dir(strFilePath) <> "" Then Kill strFilePath
        Set oStream = CreateObject("ADODB.Stream")
        oStream.Open
        oStream.Type = 1
        oStream.Write oXMLHTTP.responseBody
        oStream.SaveToFile strFilePath
        oStream.Close
    End If
End Sub

Open in new window

Hi Dave,

I hope you are well.  Thanks for the hyperlinks.

I joined VBAExpress.com & never got on with the colour scheme.

Then Experts-Exchange.com changed design/colours as well & I lost interest in participating at either site.

Do you still have textual intercourse with Matt (& Anne)?

BFN,

fp.
You're welcome, Sandesh555.
Hi Nigel,

Much the same here, I chip in now and again to get premium every two months to avoid adds when when I'm reading or contributing to the Expert thread.  I spend my time elsewhere these days

I have had sporadic email exchanges with Matt having finally met him in the flesh at an EE get together early last year. Anne has pretty much dropped out of contact, last time I spoke to one of her good Word buddy's they hadn't heard from her for a while

Cheers

Dave