Solved

Save PDF Open in Internet Explorer using VB

Posted on 2012-03-21
5
1,775 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Phishing attempts can come in all forms, shapes and sizes. No matter how familiar you think you are with them, always remember to take extra precaution when opening an email with attachments or links.
This article describes two methods for creating a combo box that can be used to add new items to the row source -- one for simple lookup tables, and one for a more complex row source where the new item needs data for several fields.
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
With Microsoft Access, learn how to start a database in different ways and produce different start-up actions allowing you to use a single database to perform multiple tasks. Specify a start-up form through options: Specify an Autoexec macro: Us…

705 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