Microsoft's UIAutomation is very powerful and works well with windows 7, 8, 10 also from visual databases for applications (32 and 64 bits) and can be convenient for performing some beautiful GUI automation without expensive tools.
Make sure there are UIAutomationCore.Dll links in the VBA link (and rather strange, sometimes on some computers you need to copy this to the documents folder)
Below you can see 2 basic examples, but since MS Automation is a huge library for all procedures, you can read a lot in MSDN for full documentation. I use MS UIA routines in AutoIt and in VBA
- For AutoIt, share it here
https://www.autoitscript.com/forum/topic/153520-iuiautomation-ms-framework-automate-chrome-ff-ie/
Explicit option
Sub test() Dim c As New CUIAutomation Dim oDesktop As IUIAutomationElement Set oDesktop = c.GetRootElement Debug.Print oDesktop.CurrentClassName & vbTab & oDesktop.CurrentName & vbTab & oDesktop.CurrentControlType End Sub 'Test uia just dumps all windows of the desktop to the debug window Sub testUIA() Dim allEl As IUIAutomationElementArray 'Returns an element array with all found results Dim oElement As IUIAutomationElement 'Reference to an element Dim ocondition As IUIAutomationCondition Dim i As Long Dim x As New clsUIA 'Just reference the three mainly used properties. many more are available when needed Debug.Print x.oDesktop.CurrentName & x.oDesktop.CurrentClassName & x.oDesktop.CurrentControlType Set ocondition = x.oCUIAutomation.CreateTrueCondition 'Filter on true which means get them all Set allEl = x.oDesktop.FindAll(TreeScope_Children, ocondition) 'Find them in the direct children, unfortunately hierarchies are strange sometimes 'Just reference the three mainly used properties. many more are available when needed For i = 0 To allEl.Length - 1 Set oElement = allEl.GetElement(i) ' If oElement.CurrentClassName = "PuTTY" Then Debug.Print oElement.CurrentClassName & oElement.CurrentName & oElement.CurrentControlType ' Debug.Print oElement.CurrentBoundingRectangle oElement.SetFocus DoEvents Sleep 2000 ' End If Next End Sub
source share