Click on an IE Window without SendKeys or MouseEvent - VBA

怎甘沉沦 提交于 2019-12-13 07:28:19

问题


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

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

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

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


回答1:


works perfectly with the code below:

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

End Sub



来源:https://stackoverflow.com/questions/37664260/click-on-an-ie-window-without-sendkeys-or-mouseevent-vba

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!