单击没有SendKeys或MouseEvent的IE窗口-VBA [英] Click on an IE Window without SendKeys or MouseEvent - VBA

查看:247
本文介绍了单击没有SendKeys或MouseEvent的IE窗口-VBA的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我必须在显示的下载窗口中单击保存. 我想使用VBA,但不使用sendkeys或mouseevent. 我希望有一些类似的东西: VBA Internet Explorer Automation-如何选择打开"下载文件时

I have to click on SAVE in Download Window shown attached. I want do it using VBA but not using sendkeys or mouseevent. I wish something smiliar this: VBA Internet Explorer Automation - How to Select "Open" When Downloading a File

请参见随附的具有按钮的窗口以及这些窗口中的属性(使用AutoIT获取)以及下面的简历:

See attached the windows that has the button and the properties from these windows (got using AutoIT) and a resume below:

下载窗口:下载窗口 AutoIT窗口属性: AutoIT窗口属性1

Download Window: Download Window AutoIT Window Properties: AutoIT Window Properties 1

窗口
标题:Windows Internet Explorer
类别:#32770
位置:1672、227
大小:391,287
样式:0x96C80284
ExStyle:0x00010101
手柄:0x005002D6

控制
类别:纽扣
实例:1
类别名称NN:Button1
姓名:
高级(班级):[CLASS:Button;实例:1]
ID:
文字:& Open
位置:10、114
大小:365、40
ControlClick坐标:302、30
样式:0x5000200F
ExStyle:0x00000000
手柄:0x0048073C

可见文字
& Open
& Save
另存为
取消

Window
Title: Windows Internet Explorer
Class: #32770
Position: 1672, 227
Size: 391, 287
Style: 0x96C80284
ExStyle: 0x00010101
Handle: 0x005002D6

Control
Class: Button
Instance: 1
ClassnameNN: Button1
Name:
Advanced (Class): [CLASS:Button; INSTANCE:1]
ID:
Text: &Open
Position: 10, 114
Size: 365, 40
ControlClick Coords: 302, 30
Style: 0x5000200F
ExStyle: 0x00000000
Handle: 0x0048073C

Visible Text
&Open
&Save
Save &as
Cancel

推荐答案

与以下代码完美配合:

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

结束子

这篇关于单击没有SendKeys或MouseEvent的IE窗口-VBA的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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