Solved

Save PDF Open in Internet Explorer using VB

Posted on 2012-03-21
5
1,642 Views
Last Modified: 2012-06-21
I need to save a PDF document that opens in a web browser.  Because of the security on the site, I have to log into the site through the code and then click on the link and have it open in a web browser.  I need to have it as though I were clicking on the save button and entering a file location, but without any user interaction.

I have all of it working, but I can't figure out how to save the PDF without any user interaction.  SendKeys is not an option in this case.

Below is an example that doesn't require the username and password, but can be used for testing.

http://image.email-freedommortgage.com/lib/fefa1577716001/m/2/WR+Wholesale+03-21-12+pc.pdf

Attached is the beginning of the code that logs into the site and navigates to the document I need to save.  Unfortunately, this will just be an example as I can't provide the login information.

Thanks!!

Set ie = CreateObject("internetexplorer.application")
ie.Visible = FALSE
ie.navigate urlMain
    While ie.Busy
        DoEvents
    Wend
    While ie.readyState <> 4
        DoEvents
    Wend
ie.Document.all("userID").Value = un
ie.Document.all("password").Value = pw
ie.Document.Forms("LoginForm").submit
    While ie.Busy
        DoEvents
    Wend
    While ie.readyState <> 4
        DoEvents
    Wend
urlXls = "https://www.freedomwholesale.com/wps/PA_WWolesaleDocuments/DocumentDownloadRequestor?sessionKey=PC_5_QBKMPI42006K5027M6UPHC20O4n17422_documentsList&channel=null&index=0"
ie.navigate urlxls

Open in new window

0
Comment
Question by:rsburge
  • 3
  • 2
5 Comments
 
LVL 17

Expert Comment

by:vb_elmar
ID: 37751039
Microsoft writes on its website...
http://support.microsoft.com/kb/244757/EN-US/
when downloading a file with WebBrowser control (or Internet Explorer) there's absolutely no way to suppress the prompt asking for saving (or opening) the file.

So additionally to the method ...
CreateObject("internetexplorer.application")
... we have to use the "URLDownloadToFile" method :

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

Private Sub Command2_Click()
myURL = "http://image.email-freedommortgage.com/lib/fefa1577716001/m/2/WR+Wholesale+03-21-12+pc.pdf"
returnValue = URLDownloadToFile(0, myURL, "C:\1.pdf", 0, 0)
MsgBox returnValue = False 'if returnValue = False then SUCCESS!
End Sub
0
 

Author Comment

by:rsburge
ID: 37751280
Thank you.

I do use a function similar to this to download many of my files, but it doesn't work with this file because of the security on the site.  I will try this method and see if it works.

Thanks!
0
 

Author Comment

by:rsburge
ID: 37754802
Hi - unfortunately, this isn't working with the security on this site.  The resulting file throws an error when opening it stating I need to go to the site and download or save it from there.

Do I have any other options for saving this PDF file besides using send keys?

Can I force this to open in Acrobat rather than in the browser?

Thanks!
0
 
LVL 17

Accepted Solution

by:
vb_elmar earned 500 total points
ID: 37755447
If you can uncheck the checkbox...
"always ask before opening this type of file"
 (see attached image)
...the "File Download" Dialog would not pop up.

Then you could use the command...
ie.ExecWB 4, 2   'SAVE  FILE  AS  
or
ie.ExecWB 6, 2   'PRINT  the  File              

...to SAVE or PRINT the file.

THE CONSTANTS ARE :
============================
Const OLECMDID_PRINT = 6
Const OLECMDEXECOPT_DONTPROMPTUSER = 2
Const OLECMDID_SAVEAS = 4
dialog1.jpg
0
 

Author Comment

by:rsburge
ID: 37755492
Thank you!  I appreciate your help!
0

Featured Post

Three Reasons Why Backup is Strategic

Backup is strategic to your business because your data is strategic to your business. Without backup, your business will fail. This white paper explains why it is vital for you to design and immediately execute a backup strategy to protect 100 percent of your data.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
A simple tool to export all objects of two Access files as text and compare it with Meld, a free diff tool.
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

790 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question