title: How to download a pdf file from browser using Excel VBA
body: <p>I am using the below code snippet to download a PDF file from a website.</p>
  
  <pre><code>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
  
  Sub Test()
      Dim strPDFLink As String
      Dim strPDFFile As String
      Dim Result As Boolean
      strPDFLink = "myurl?SessionKey=rCpZeX9UP300002D50BA&amp;  docid=*8G0leLEfTTX3oX8QpVUmKqRoTj6zS6bzTWf9%29Dt1hij3ym9hKqucLhtOnWVeCgM0wyGJyjI9RNj3Kv&amp;PageNo=1"
      strPDFFile = "D:\Users\d828737\Desktop\Doc Comparison\Temp\abcd.pdf"
      Result = DownloadFile(strPDFLink, strPDFFile)
  End Sub
  
  Function DownloadFile(URL As String, LocalFilename As String) As   Boolean
      Dim lngRetVal As Long
      lngRetVal = URLDownloadToFile(0, URL, LocalFilename, 0, 0)
      If lngRetVal = 0 Then DownloadFile = True
  End Function
  
  Below is the response i am getting from browser using code
     &lt;html&gt;
     &lt;head&gt;
    &lt;META http-equiv="Content-Type" content="text/html; charset=UTF-8"&gt;
    &lt;title&gt;Interview Enterprise Web Client&lt;/title&gt;
    &lt;/head&gt;
    &lt;frameset name="ImageFrame" border="1" framespacing="0" topmargin="0"   leftmargin="0" marginheight="0" marginwidth="0" rows="*,80"&gt;
    &lt;frame name="document" src="iv_web_client.iv_document?SessionKey=1aYT4sGK1200002D50C6&amp;amp;docid=*8G0SU4Fcf)xcWWX6e96)FGlOL4rOYYt0i3m)HlGth2F(W4RnxurPClkHvNBurOAsaeNfGlwBKzzTm5&amp;amp;outputname=&amp;amp;FirstPage=1&amp;amp;options=" scrolling="auto" border="0" frameborder="no" topmargin="0" leftmargin="0" marginheight="0" marginwidth="0" style="border-bottom:solid#000000 1px;" noresize=""&gt;
    &lt;frame name="control" src="iv_web_client.iv_doc_sel?SessionKey=1aYT4sGK1200002D50C6&amp;amp;docid=*8G0SU4Fcf)xcWWX6e96)FGlOL4rOYYt0i3m)HlGth2F(W4RnxurPClkHvNBurOAsaeNfGlwBKzzTm5&amp;amp;outputname=&amp;amp;pageno=1&amp;amp;options=" scrolling="auto" border="0" frameborder="no" topmargin="0" leftmargin="0" marginheight="0" marginwidth="0" style="border-bottom:solid#000000 1px;" noresize=""&gt;
    &lt;/frameset&gt;
    &lt;noframes&gt;You need a frames capable browser to use this site.&lt;/noframes&gt;
   &lt;/html&gt;
  </code></pre>
  
  <p>I have also tried the below method</p>
  
  <pre><code>Set WHTTP = CreateObject("WinHTTP.WinHTTPrequest.5.1")
  WHTTP.Open "GET", fileUrl, False
  WHTTP.Send
  FileData = WHTTP.ResponseBody
  </code></pre>
  
  <p>when i open the url given in the above code in browser,i can see pdf file getting opened automatically.How do i download the same pdf file opened in my browser using code?</p>
  
  <p>Can some one help me to resolve the issue.</p>