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

Can a formula spear through sheets?
Use =SUM(January:December!E7) to sum E7 on all of the sheets from January through December
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,224,823
Messages
6,181,179
Members
453,021
Latest member
Justyna P

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