1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94
| Option Explicit
Dim oAppCible
Sub TEST_SelectRibbonTab()
If UCase(Application) = "OUTLOOK" Then
Set oAppCible = Application
Else
Set oAppCible = CreateObject("outlook.application")
End If
Call SelectRibbonTab("gSyncit")
Call ClicButton("Sync Calendars")
End Sub
Public Sub SelectRibbonTab(NAME)
Dim uiAuto As UIAutomationClient.CUIAutomation
Dim elmRibbon As UIAutomationClient.IUIAutomationElement
Dim elmRibbonTab As UIAutomationClient.IUIAutomationElement
Dim cndProperty As UIAutomationClient.IUIAutomationCondition
Dim aryRibbonTab As UIAutomationClient.IUIAutomationElementArray
Dim ptnAcc As UIAutomationClient.IUIAutomationLegacyIAccessiblePattern
Dim accRibbon As Office.IAccessible
Dim i As Long
Set elmRibbonTab = Nothing '???
Set uiAuto = New UIAutomationClient.CUIAutomation
If InStr(1, oAppCible.NAME, "Outlook", vbTextCompare) > 0 Then
If TypeName(oAppCible.ActiveWindow) = "Inspector" Then
Set accRibbon = oAppCible.activeinspector.CommandBars("Ribbon")
ElseIf TypeName(oAppCible.ActiveWindow) = "Explorer" Then
Set accRibbon = oAppCible.activeexplorer.CommandBars("Ribbon")
End If
Else
Set accRibbon = oAppCible.CommandBars("Ribbon")
End If
Set elmRibbon = uiAuto.ElementFromIAccessible(accRibbon, 0)
Set cndProperty = uiAuto.CreatePropertyCondition(UIA_ClassNamePropertyId, "NetUIRibbonTab")
Set aryRibbonTab = elmRibbon.FindAll(TreeScope_Subtree, cndProperty)
For i = 0 To aryRibbonTab.Length - 1
Set elmRibbonTab = aryRibbonTab.GetElement(i)
If Not elmRibbonTab Is Nothing Then
If elmRibbonTab.CurrentControlType = UIA_TabItemControlTypeId And StrComp(elmRibbonTab.CurrentName, NAME, vbTextCompare) = 0 Then
Set ptnAcc = elmRibbonTab.GetCurrentPattern(UIA_LegacyIAccessiblePatternId)
ptnAcc.DoDefaultAction
DoEvents
Exit For
End If
End If
Next
If ptnAcc Is Nothing Then
End If
End Sub
Public Sub ClicButton(ByVal BoutonName As String)
Dim uiAuto As UIAutomationClient.CUIAutomation
Dim elmRibbon As UIAutomationClient.IUIAutomationElement
Dim elmRibbonTab As UIAutomationClient.IUIAutomationElement
Dim cndProperty As UIAutomationClient.IUIAutomationCondition
Dim aryRibbonTab As UIAutomationClient.IUIAutomationElementArray
Dim ptnAcc As UIAutomationClient.IUIAutomationLegacyIAccessiblePattern
Dim accRibbon As Office.IAccessible
Dim i As Long
Set elmRibbonTab = Nothing '???
Set uiAuto = New UIAutomationClient.CUIAutomation
Set accRibbon = oAppCible.activeexplorer.CommandBars("Ribbon")
Set elmRibbon = uiAuto.ElementFromIAccessible(accRibbon, 0)
' Set cndProperty = uiAuto.CreatePropertyCondition(UIA_ClassNamePropertyId, "NetUIRibbonTab")
Set cndProperty = uiAuto.CreatePropertyCondition(UIA_ClassNamePropertyId, "NetUIRibbonButton")
Set aryRibbonTab = elmRibbon.FindAll(TreeScope_Subtree, cndProperty)
For i = 0 To aryRibbonTab.Length - 1
Debug.Print aryRibbonTab.GetElement(i).CurrentName
If aryRibbonTab.GetElement(i).CurrentName = BoutonName Then
Set elmRibbonTab = aryRibbonTab.GetElement(i)
Exit For
End If
Next
If elmRibbonTab Is Nothing Then Exit Sub
Set ptnAcc = elmRibbonTab.GetCurrentPattern(UIA_LegacyIAccessiblePatternId)
ptnAcc.DoDefaultAction
End Sub |
Partager