Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
285 views
in Technique[技术] by (71.8m points)

VBA Internet Explorer Automation - How to Select "Open" When Downloading a File

This is my first question ever here on stackoverflow!

I've been searching for a solution to this problem for a while and haven't found any help. I may just be using the wrong keywords in my searches, but so far I've had no luck. Here's the question:

In VBA, how can I select the "Open" option from the file download dialog in Internet Explorer?

Just for extra clarification, I'm talking about the yellow-orange bar that pops up across the bottom of the screen in IE9 when a file is downloaded.

I'm doing some VBA automation to download hundreds of PDFs from the web using Internet Explorer, but there is an intermediate step where a .fdf file has to be opened before I get to the actual PDF. So I first need to select the "Open" option so that I can move on to the next step of the automation. Like I said earlier, I've done a lot of searching and had no luck so far.

I've tried using SendKeys in hopes that hitting Enter would work, and that was a last ditch effort that didn't work.

Thanks in advance for the help!

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

I have covered this extensively here.

Topic: VBA/VB.Net/VB6–Click Open/Save/Cancel Button on IE Download window – PART I

Link: http://www.siddharthrout.com/2011/10/23/vbavb-netvb6click-opensavecancel-button-on-ie-download-window/

and


EDIT (IMP) If you are using IE 9 Do not forget to read PART 2 as it includes and covers the window structure of IE 9 download window


Topic: VBA/VB.Net/VB6–Click Open/Save/Cancel Button on IE Download window – PART II

Link: http://www.siddharthrout.com/2012/02/02/vbavb-netvb6click-opensavecancel-button-on-ie-download-window-part-ii/

The above links discuss on how to use use the API's to achieve what you want.

From the 1st link...

Like you and me, we both have names, similarly windows have “handles” (hWnd), Class etc. Once you know what that hWnd is, it is easier to interact with that window.

Findwindow API finds the hWnd of a particular window by using the class name and the caption of the window (“File Download”) in this case. The “Open“, “Save” and “Cancel” buttons are windows in itself but they are child windows of the main window which is “File Download“. That means each one of those will also have a hWnd :) To find the child windows, we don’t use FindWindow but use FindWindowEx. All the three buttons “Open“, “Save” and “Cancel” have the same class which is “ Button”.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...