If this is your first visit, be sure to
check out the FAQ by clicking the
link above. You may have to register
before you can post: click the register link above to proceed. To start viewing messages,
select the forum that you want to visit from the selection below.

IE Download File Prompt

Hi All,

I am in the process of making a Macro to automate a tedious process I go throguh every week. I have a bunch of logins in an excel file. I have to go to an internal website/database and download an Excel file for each login. It takes the first couple of days of every week to pull the files as I have about 100 or so reports I have to pull.

With help from others on this forum which is greatly appreciated. I have compiled code to retrieve the login info from the excel file, Navigate to the website, login, navigate multiple iframes, select criteria for report, and select the "Run" button.

I am now at the point where I receive a Download File prompt to Open, Save or Cancel. I need help selecting Save and then selecting a path to save the file.

I have seen the API Downloadfile code but I do not have a known URL. The end of the URL has a "#" instead of a report number or anything to identify it by.

Re: IE Download File Prompt

you can use APIs findwindow or similar to determine when the dialog is open, then sendmessage to submit a value to it

or if you can return the value (url) of the webquery before submitting the form, you can use urldownloadtofile API

i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next

dim all variablesas required as often i have done so elsewhere in my code but only posted the relevant part

come back and mark your original post as resolved if your problem is fixed
pete

Re: IE Download File Prompt

I found the code below but I am having trouble getting it to run. It was setup on windows xp. It finds the File download window and clicks save it then finds the save as prompt. Then I can not get it to recognize the child window "Edit" to change the file name.

My problem is first I can not find or do not know how to obtain the download URL. Any suggestion would be great.

I also get a type mismatch error on the following line: Save_As_Set_Filename saveInFolder, saveFilename. Is you can tell I am fairly new to coding. For me this is somewhat complex and all the guidence I get is very much appreciated.

Re: IE Download File Prompt

i would love to be able to use the urldownloadtofile but my problem is that I dont know how to determine the URL.....

The site/database that I have to go to first requires me to login then fill out a bunch of info. Then I click a button that says "RUN" which runs the javascript that I have above... The URL in the URL bar stays the same throughout the whole process not matter what I select. Once I hit the run button the File Download dialog box pops up.

How do I determine the URL that has prompted the file download box?

Forgive me but i dont know how to use APIs and I have been searching the internet for almost 2 weeks now. Ha, my frustration comes from this is literally the last step.

Re: IE Download File Prompt

thanks mawdo. May i know why we have to wait 30 seconds ? as far as i can see the codes assumes the file download windows is already visable!

May i know why findwindow is inside "do loop untill" ? it would be nice if you explain it to me.Furthermore more is it possible to click both save and save as buttons and click download button inside one function? How?(For example how i can make the function so it clicks the download button then waits for it to pop up and then clicks both save and save as buttons ?)

Re: IE Download File Prompt

as far as i can see the codes assumes the file download windows is already visable!

probably not, i would assume this code is called immediately on clicking the download button, so the dialog would not be visible yet

pop up and then clicks both save and save as buttons ?

i do not believe this would be possible, anymore than you can click both buttons manually, only one would work
also if you click the saveAs a further dialog would show to ask for a filepath\name, which you would also have to findwindow and sendmessage
to do both you would have to click the download button again after processing the first request

i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next

dim all variablesas required as often i have done so elsewhere in my code but only posted the relevant part

come back and mark your original post as resolved if your problem is fixed
pete

Re: IE Download File Prompt

Thanks guys for reply. Mawdo why your code will not work if the download button is clicked from webrowser control that is in same project as your code(i added small code at start of your code that clicks download button inside webbrowser control) ?The File_Download_Click_Save button is cant be clicked when file download pops up!!the project form is locked so i can't click the button!is there a way to fix this ?

Re: IE Download File Prompt

the project form is locked so i can't click the button!is there a way to fix this ?

you are not giving enough information as to what is happening, we can only assume that the code is staying within a loop or something, not able to find the correct window
you have not posted your own code, so we can not know what changes you may have made

as you are using a webbrowser control there may be some event that you can have that will avoid having to wait til the dialog has loaded

i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next

dim all variablesas required as often i have done so elsewhere in my code but only posted the relevant part

come back and mark your original post as resolved if your problem is fixed
pete

Re: IE Download File Prompt

Hey Tony, is the javascript in the forms the only thing that is keeping you from using a different method? Is the javascript so complex that what it does would be real cumbersome to replicate? The reason I'm asking is that findwindow and sendmessage with the save as dialog is kludgy. It may get you going at first, but will cause you more problems in the long run. There's no guarantee that the dialog will appear when you submit, MS might break this by altering how IE behaves in the future, a mysterious dialog message could pop up from IE before the save dialog and "freeze" IE, etc.