[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

Save PDF Open in Internet Explorer using VB

Posted on 2012-03-21
5
Medium Priority
?
2,036 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 2000 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

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

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

In earlier versions of Windows (XP and before), you could drag a database to the taskbar, where it would appear as a taskbar icon to open that database.  This article shows how to recreate this functionality in Windows 7 through 10.
Access developers frequently have requirements to interact with Excel (import from or output to) in their applications.  You might be able to accomplish this with the TransferSpreadsheet and OutputTo methods, but in this series of articles I will di…
In Microsoft Access, learn how to use Dlookup and other domain aggregate functions and one method of specifying a string value within a string. Specify the first argument, which is the expression to be returned: Specify the second argument, which …
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…
Suggested Courses

656 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