问题描述
我正在尝试识别 Word 是否是从 Excel 启动的。
问题似乎是导致错误的 Word-Splash。如果函数是在 Word 启动之后启动的,则它可以正常工作。
Function FindyEdByClass() As iuiAutomationElement
Dim oUIAutomation As New CUIAutomation
Dim oUIADesktop As iuiAutomationElement
Dim allChilds As iuiAutomationElementArray
Dim oUIAWord As iuiAutomationElement
Dim i As Integer
Dim Timer As Date
Set oUIADesktop = oUIAutomation.GetRootElement
Set oUIAWord = oUIADesktop
Timer = Now
RestartLoop:
Set allChilds = oUIADesktop.FindAll(TreeScope_Children,oUIAutomation.CreateTrueCondition)
Debug.Print "StartLoop" & vbCrLf;
For i = 0 To allChilds.length - 1
If allChilds.GetElement(i).CurrentName Like "*Word*" Then
'And allChilds.GetElement(i).CurrentClassName = "SunAwtFrame" Then
Set oUIAWord = allChilds.GetElement(i)
End If
Next
If Now() > (Timer + TimeValue("00:00:15")) Then GoTo Noword
If oUIAWord.CurrentName Like "DesktoP*" Then GoTo RestartLoop
EndOFLoop:
Debug.Print oUIAWord.CurrentName & " " & oUIAWord.CurrentClassName & vbCrLf;
Set FindyEdByClass = oUIAWord
Exit Function
Noword:
Debug.Print "No Word found"
End
End Function
For Next 循环中发生错误:
For i = 0 To allChilds.length - 1
**If allChilds.GetElement(i).CurrentName Like "*Word*" Then**
Set oUIAWord = allChilds.GetElement(i)
End If
Next
是否有修复或更好的方法?
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)