Solved

Save PDF Open in Internet Explorer using VB

Posted on 2012-03-21
5
1,528 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

Complete Microsoft Windows PC® & Mac Backup

Backup and recovery solutions to protect all your PCs & Mac– on-premises or in remote locations. Acronis backs up entire PC or Mac with patented reliable disk imaging technology and you will be able to restore workstations to a new, dissimilar hardware in minutes.

Join & Write a Comment

Experts-Exchange is a great place to come for help with solutions for your database issues, and many problems are resolved within minutes of being posted.  Others take a little more time and effort and often providing a sample database is very helpf…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Familiarize people with the process of retrieving data from SQL Server using an Access pass-thru query. Microsoft Access is a very powerful client/server development tool. One of the ways that you can retrieve data from a SQL Server is by using a pa…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

708 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now