VBA Internet Explorer 自动化 - 如何选择“打开"下载文件时 [英] VBA Internet Explorer Automation - How to Select "Open" When Downloading a File

查看:45
本文介绍了VBA Internet Explorer 自动化 - 如何选择“打开"下载文件时的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我在 stackoverflow 上的第一个问题!

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:

在 VBA 中,如何从 Internet Explorer 的文件下载对话框中选择打开"选项?

为了额外说明,我指的是下载文件时在 IE9 屏幕底部弹出的橙黄色条.

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.

我正在执行一些 VBA 自动化操作,以使用 Internet Explorer 从网络下载数百个 PDF,但有一个中间步骤,在我获得实际 PDF 之前,必须打开 .fdf 文件.所以我首先需要选择打开"选项,以便我可以继续下一步的自动化.就像我之前说的,我已经做了很多搜索,但到目前为止都没有运气.

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.

我曾尝试使用 SendKeys,希望按 Enter 会奏效,但这是最后一次失败的尝试.

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

预先感谢您的帮助!

推荐答案

我已经在这里进行了广泛的讨论.

I have covered this extensively here.

主题:VBA/VB.Net/VB6——在IE下载窗口点击打开/保存/取消按钮——第一部分

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

EDIT (IMP) 如果您使用的是 IE 9 不要忘记阅读第 2 部分,因为它包括并涵盖了 IE 9 下载窗口的窗口结构

主题:VBA/VB.Net/VB6——在IE下载窗口点击打开/保存/取消按钮——第二部分

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

以上链接讨论了如何使用 API 来实现您想要的.

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

从第一个链接...

就像你和我一样,我们都有名字,同样的窗口有句柄"(hWnd)、类等.一旦你知道 hWnd 是什么,与那个窗口交互就更容易了.

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 使用类名和窗口标题(文件下载")来查找特定窗口的 hWnd.打开"、保存"和取消"按钮本身是窗口,但它们是文件下载"主窗口的子窗口.这意味着它们中的每一个也将有一个 hWnd :) 为了找到子窗口,我们不使用 FindWindow,而是使用 FindWindowEx.打开"、保存"和取消"这三个按钮都具有相同的类,即按钮".

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".

这篇关于VBA Internet Explorer 自动化 - 如何选择“打开"下载文件时的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆