UI automation RRS feed

  • Question

  • So we just discovered how we can reference the UIAUTOMATIONCORE.DLL at Excel
    our question is how to use it, we can't find documentations and concept of it that uses VB

    all concept i found is for C

    can someone help me how to use it? or can someone point me to a guide or something

    and where to we find uiautomationtypes.dll


    Wednesday, December 3, 2014 8:16 AM

All replies

  • hi 

    Use the below code to set root element or base window and get all the elements list in sheet 1 to set the element.

    open the calculator

            Public Enum oConditions
    End Enum

    Private Sub Command2_Click()
    Dim element As UIAutomationClient.IUIAutomationElement
    CurrentDb.Execute ("delete * from ELEMENT_PROPERTIES")
    Set appobj = WalkEnabledElements("Calculator")
    thisworkbook.sheet(1).range("a1") = "Value"
        thisworkbook.sheet(1).range("b1") ="ClassName"
        thisworkbook.sheet(1).range("c1") = "AutomationId"
        thisworkbook.sheet(1).range("d1") = "currentname"
        thisworkbook.sheet(1).range("e1") = "LocalizedControlType"
        thisworkbook.sheet(1).range("f1") = "currentisenabled"
    Call GetElement(appobj)
    End Sub

    Function GetElement(elementalist As UIAutomationClient.IUIAutomationElement)

    On Error Resume Next
    Dim oAutomation As New CUIAutomation
    Dim walker As UIAutomationClient.IUIAutomationTreeWalker

    Set walker = oAutomation.ControlViewWalker

    Dim element1 As UIAutomationClient.IUIAutomationElementArray
    Dim element2 As UIAutomationClient.IUIAutomationElement
    Dim childtree As UIAutomationClient.TreeScope
    Dim condition1 As UIAutomationClient.IUIAutomationCondition

    Set condition1 = oAutomation.CreateTrueCondition
    Set element1 = elementalist.FindAll(TreeScope_Children, condition1)
    If element1.Length <> 0 Then
        Set element2 = elementalist.FindFirst(TreeScope_Children, condition1)
    End If

    Do While Not element2 Is Nothing
    Dim oPattern As UIAutomationClient.IUIAutomationLegacyIAccessiblePattern
    Set oPattern = element2.GetCurrentPattern(UIA_LegacyIAccessiblePatternId)
    Set rs = CurrentDb.OpenRecordset("select * from ELEMENT_PROPERTIES")

        thisworkbook.sheet(1).range("a"&i) = oPattern.CurrentValue
        thisworkbook.sheet(1).range("b"&i) = element2.CurrentClassName
        thisworkbook.sheet(1).range("c"&i) = element2.CurrentAutomationId
        thisworkbook.sheet(1).range("d"&i) = element2.currentname
        thisworkbook.sheet(1).range("e"&i) = element2.CurrentLocalizedControlType
        thisworkbook.sheet(1).range("f"&i) = element2.currentisenabled
        thisworkbook.sheet(1).range("g"&i)= element2.CurrentHelpText

        GetElement element2

        If Not myelement Is Nothing Then Exit Function
        Set element2 = walker.GetNextSiblingElement(element2)


    End Function

    once you got the element list with property details in first page. use them to do your action.

    sub invokeing_element()

    Dim appobjAs UIAutomationClient.IUIAutomationElement

    Dim myelement As UIAutomationClient.IUIAutomationElement

    Dim invokw  As UIAutomationClient.IUIAutomationInvokePattern

    Set appobj = WalkEnabledElements("Calculator")

    Set myelement = appobj.FindFirst(TreeScope_Descendants, PropCondition(oAutomation, eUIA_NamePropertyId, "8"))

    Set invokw = myelement .GetCurrentPattern(UIAutomationClient.UIA_PatternIds.UIA_WindowPatternId)
    invokw .invoke

    end sub

    tadath!..see the calculator window now number 8 button clicked.

    Friday, February 21, 2020 9:02 AM