Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
617 views
in Technique[技术] by (71.8m points)

user interface - UI automation with excel

I am new to UI Automation. In my current organisation I was tasked with making an automated tool using GUI(Graphics User Interface) screen reading, but it is not working perfectly with other my colleague's machine because of a difference in screen resolution.

I watched this link on you-tube to try and understand UI Automation with excel, but I can't find much on this topic anywhere else.

Can anyone direct me toward resources on UI Automation? I Would like to know where I can learn it, read about it, and how to implement it with Excel.

Thanks in advance I really appreciate if anyone could help me.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

UIAutomation from Microsoft is very powerfull and works well with windows 7, 8, 10 also from visual basic for applications (32 and 64 bits) and can be handy used to do some nice GUI Automation without expensive tools.

Make sure in VBA reference you have UIAutomationCore.Dll references (and weird enough sometimes on some computers you have to copy this to your documents folder)

Below you can see 2 base examples but as MS Automation is a huge library for all routines you can read a lot on MSDN for full documentation. I use the MS UIA routines in AutoIt and in VBA

  • For AutoIt its shared over here

https://www.autoitscript.com/forum/topic/153520-iuiautomation-ms-framework-automate-chrome-ff-ie/

Option Explicit

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    

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...