How to save PDF from link or manipulate Adobe

pitaszek

Board Regular
Joined
Jul 20, 2012
Messages
85
Hi guys,

As starts with the link I have (it won't work for you but it's not important):

http://cwzproxy.com:8080/STVService...id=&toolbar=true&savable=true&parentApfi=8712

This long link has not any *.PDF extensions but virtually it opens PDF.

I thought I could use this link to download the file using this code but it does not work. The file is corrupt.
Code:
Sub Downloadpdf ()
 
Dim myURL As String
myURL = "http://cwzproxy.com:8080/STVService/[...]=&toolbar=true&savable=true&parentApfi=8712"
 
Dim WinHttpReq As Object
Set WinHttpReq = CreateObject("Microsoft.XMLHTTP")
WinHttpReq.Open "GET", myURL, False
WinHttpReq.Send
 
myURL = WinHttpReq.ResponseBody
    Set oStream = CreateObject("ADODB.Stream")
    oStream.Open
    oStream.Type = 1
    oStream.Write WinHttpReq.ResponseBody
    oStream.SaveToFile ("C:\Users\Python\exampledoc.pdf")
    oStream.Close
 
End Sub

Even if I cant use code to download that directly using the l inke, maybe I can control the Adobe Reader that opens the file (Starndard DC in my case), save it, close the window and loop to next one.

I tried something like this but it says there is no library:
Code:
Sub SavePDf()


Dim AcroApp As Acrobat.CAcroApp


Dim PdDoc As Acrobat.CAcroPDDoc


Dim avdoc As Acrobat.CAcroAVDoc
 


Set AcroApp = CreateObject("AcroExch.App")
  Set avdoc = AcroApp.GetActiveDoc
  If Not (avdoc Is Nothing) Then
    Set PdDoc = avdoc.GetPDDoc
    WasSaved = PdDoc.Save(PDSaveFull, "C:\Users\sobkoww\python.pdf")
  End If 


End Sub

Thanks!
 
Last edited:

Excel Facts

Square and cube roots
The =SQRT(25) is a square root. For a cube root, use =125^(1/3). For a fourth root, use =625^(1/4).
I thought I could use this link to download the file using this code but it does not work. The file is corrupt.
That code may work, as long as you send everything the web page is expecting. The corrupt file indicates something is missing, e.g. a cookie in the request headers or form data. Maybe it should be a POST instead of a GET. Use your browser's developer tools to see the requests and responses which occur when downloading manually, and send the same with VBA.

The thread at https://www.mrexcel.com/forum/excel-questions/976756-vba-download-pdf.html is along the same lines, but specific to that case.
 
Upvote 0

Forum statistics

Threads
1,223,893
Messages
6,175,249
Members
452,623
Latest member
Techenthusiast

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top