VBA Web Download File Control

susieq324

New Member
Joined
Jun 25, 2011
Messages
3
I've written VBA code to invoke a webpage, enter a user ID, pwd, hit Logon. When the next page comes up, it requires the user to click "Download" so that the file given will open up and I've gotten the VBA code to accomplish this.

What I haven't figured out is then how to control the IE File commands that open prompting me to either Open, Save the file or Cancel the operation.

I've tried SendKeys but that just creates keystrokes in my Excel VBA code. (*doh*). Are there certain HTML tags that these commands refer to universally or is there some other trick to get it to then pass the "Open" command and keep going?
 

Excel Facts

Move date out one month or year
Use =EDATE(A2,1) for one month later. Use EDATE(A2,12) for one year later.
What I haven't figured out is then how to control the IE File commands that open prompting me to either Open, Save the file or Cancel the operation.
You could try my code in this thread - http://www.mrexcel.com/forum/showthread.php?t=507871 - which automates the sequence of IE download file windows. I've since updated the code to handle the '< file > already exists. Do you want to replace it?' window.

There are some questions and answers about the code in this thread - http://www.mrexcel.com/forum/showthread.php?t=502298.

Post back here if you need further help.
 
Upvote 0
Thanks for the code - I get where you were going with it. What I'm finding is that it's no longer compatible with IE8 or 9.

When I click the download button on my webpage, I get a little message in IE8 that "click here to verify you want to download the file". Normally, when you click it, it tells IE that you are allowed to download and then you have to reclick the download button and then I think your popup would work.

I'm assuming that this is an option that I need to turn off security for. Any suggestions?
 
Upvote 0
The code still works on IE8 - I've just tested it.

As noted in the comment at the top of the code, IE may block the download, displaying its Information Bar at the top of the tab, and preventing my program from automatically downloading the file. To prevent this, add your URL (e.g. http://www.yoursite.com) to IE's Trusted sites (Tools - Internet Options - Security - Trusted sites - Sites)
 
Upvote 0
John, I did finally get most of it to work and it was that IE option that was my first barrier. Now its all working but it isn't passing or stepping thru the ComboBoxEx32 or ComboBox if-then statements to change the directory and/or filename. It's just saving it to the default, which is the Desktop. I've watched the values and the hex(hwnd) is coming back as 0 for the first ComboBoxEx32 so that all the subsequent checks fail.

I've hit a wall on this one - everything I've tried isn't working. Its not finding the dialog for the File name: box on the Save As screen.

Any thoughts?

Sue
 
Upvote 0
Sue

If the file is getting saved to the desktop why not just move it from the desktop to where you really want it to go?

That can easily be done with the Name statement.
Code:
Dim strOldName As String
Dim strNewName As String
 
    strOldName ="C:\Desktop\downloadedfile.file"
 
    strNewName = "C:\OtherDirectory\FolderWhereFileShouldGo\downloadedfile.file"
 
    Name strOldName As strNewName
 
Upvote 0

Forum statistics

Threads
1,224,595
Messages
6,179,798
Members
452,943
Latest member
Newbie4296

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