【问题标题】:Click on an IE Window without SendKeys or MouseEvent - VBA单击没有 SendKeys 或 MouseEvent 的 IE 窗口 - VBA
【发布时间】:2016-06-06 18:19:14
【问题描述】:

我必须在附件所示的下载窗口中点击保存。 我想使用 VBA 但不使用 sendkeys 或 mouseevent。 我希望有类似的东西:VBA Internet Explorer Automation - How to Select "Open" When Downloading a File

请参阅附有按钮的窗口和这些窗口中的属性(使用 AutoIT 获得)和下面的简历:

下载窗口:Download Window AutoIT 窗口属性:AutoIT Window Properties 1

窗口
标题:Windows Internet Explorer
班级:#32770
位置:1672, 227
尺寸:391、287
款式:0x96C80284
ExStyle: 0x00010101
句柄:0x005002D6

控制
类:按钮
实例:1
类名NN:Button1
名称:
高级(类):[CLASS:按钮;实例:1]
编号:
文本:&打开
位置:10、114
尺寸:365、40
ControlClick 坐标:302、30
样式:0x5000200F
ExStyle: 0x00000000
句柄:0x0048073C

可见文本
&打开
保存(&S)
另存为&as
取消

【问题讨论】:

  • 你可以使用 IE 的 DOM 浏览器来查找元素吗?也许您可以只使用 JavaScript 来单击元素。

标签: vba internet-explorer automation


【解决方案1】:

与以下代码完美配合:

Sub Download()
Dim o As IUIAutomation
Dim e As IUIAutomationElement
Set o = New CUIAutomation
h = ie.hwnd
h = FindWindow("#32770", vbNullString)
If h = 0 Then Exit Sub

Set e = o.ElementFromHandle(ByVal h)
Dim iCnd As IUIAutomationCondition
Set iCnd = o.CreatePropertyCondition(UIA_NamePropertyId, "Save")

Dim Button As IUIAutomationElement
Set Button = e.FindFirst(TreeScope_Subtree, iCnd)
Dim InvokePattern As IUIAutomationInvokePattern
Set InvokePattern = Button.GetCurrentPattern(UIA_InvokePatternId)
InvokePattern.Invoke

结束子

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-02-19
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多