0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

VBA の UI Automation で部分一致検索する

Posted at

IUIAutomation::CreatePropertyConditionEx で第3引数に PropertyConditionFlags_MatchSubstring を指定することで部分一致条件での検索が実施されます。

Sub Excelをタイトルに含むChromeブラウザを取得する()
  Dim uia As CUIAutomation8: Set uia = New CUIAutomation8
  Dim root As IUIAutomationElement: Set root = uia.GetRootElement
  ' Chromeのウィンドウを探す
  Dim cnd1 As IUIAutomationCondition: Set cnd1 = uia.CreatePropertyCondition(UIA_ClassNamePropertyId, 
  "Chrome_WidgetWin_1")
  ' CreatePropertyConditionExの第3引数にPropertyConditionFlags_MatchSubstringを指定すると部分一致で検索できる
  Dim cnd2 As IUIAutomationCondition: Set cnd2 = uia.CreatePropertyConditionEx(UIA_NamePropertyId, "Excel", PropertyConditionFlags_MatchSubstring)
  Dim cnd As IUIAutomationAndCondition: Set cnd = uia.CreateAndCondition(cnd1, cnd2)
  Dim ary As IUIAutomationElementArray: Set ary = root.FindAll(TreeScope_Children, cnd)

  Dim i As Long, elm As IUIAutomationElement
  For i = 0 To ary.Length - 1
    Set elm = ary.GetElement(i)
    ' ウィンドウのクラス名と名前を出力
    Debug.Print elm.CurrentClassName, elm.CurrentName
  Next
End Sub
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?