質問編集履歴

1

ソース追記

2023/09/18 03:58

投稿

kazuuumi
kazuuumi

スコア4

test CHANGED
File without changes
test CHANGED
@@ -12,5 +12,45 @@
12
12
  現在下記のサイトを参考に挿入タブまで選択できたのですが知識が不足しているためそちら以降の作業が分かっておりません。
13
13
  https://www.ka-net.org/blog/?p=4624
14
14
 
15
+ ###ソース
16
+ ```VBA
17
+ Option Explicit
18
+
19
+ Public Sub Sample()
20
+ SelectRibbonTab "挿入"
21
+ End Sub
22
+
23
+ Public Sub SelectRibbonTab(ByVal tabName As String)
24
+ 'リボンのタブを選択
25
+ Dim uiAuto As UIAutomationClient.CUIAutomation
26
+ Dim elmRibbon As UIAutomationClient.IUIAutomationElement
27
+ Dim elmRibbonTab As UIAutomationClient.IUIAutomationElement
28
+ Dim cndProperty As UIAutomationClient.IUIAutomationCondition
29
+ Dim aryRibbonTab As UIAutomationClient.IUIAutomationElementArray
30
+ Dim ptnAcc As UIAutomationClient.IUIAutomationLegacyIAccessiblePattern
31
+ Dim accRibbon As Office.IAccessible
32
+ Dim i As Long
33
+
34
+ Set elmRibbonTab = Nothing '初期化
35
+ Set uiAuto = New UIAutomationClient.CUIAutomation
36
+ Set accRibbon = Application.CommandBars("Ribbon")
37
+ Set elmRibbon = uiAuto.ElementFromIAccessible(accRibbon, 0)
38
+ Set cndProperty = uiAuto.CreatePropertyCondition(UIA_ClassNamePropertyId, "NetUIRibbonTab")
39
+ Set aryRibbonTab = elmRibbon.FindAll(TreeScope_Subtree, cndProperty)
40
+ For i = 0 To aryRibbonTab.Length - 1
41
+ Debug.Print "CurrentName" & aryRibbonTab.GetElement(i).CurrentName
42
+ If aryRibbonTab.GetElement(i).CurrentName = tabName Then
43
+ Set elmRibbonTab = aryRibbonTab.GetElement(i)
44
+ Exit For
45
+ End If
46
+ Next
47
+ If elmRibbonTab Is Nothing Then Exit Sub
48
+ Set ptnAcc = elmRibbonTab.GetCurrentPattern(UIA_LegacyIAccessiblePatternId)
49
+ ptnAcc.DoDefaultAction
50
+
51
+
52
+ End Sub
53
+ ```
54
+
15
55
  有識者の方、または試したことがあるかたよろしければ助言をいただきたいです。
16
56