回复 1# Heykuz
使用Split对字符串划分、生成数组,使用For Each遍历这个数组。- Const sTitle = "百度|谷歌|必应" ' 查找窗口名称,多个名称使用分割号“|”隔开
- Const nTimeOut = 5 ' 指定超时时间
- Dim dtStart, bFind, o
- dtStart = Now()
- Do While DateDiff("s", dtStart, Now()) < nTimeOut
- WScript.Sleep 200
- For Each o In Split(sTitle,"|") '遍历分组
- If Trim(o) <> "" Then
- If CreateObject("WScript.Shell").Appactivate(Trim(o)) Then
- bFind = True ' 做标记-已找到
- Exit For
- End If
- End If
- Next
- If bFind = True Then Exit Do
- Loop
- If bFind Then
- Msgbox "找到一个含有“" & sTitle & "”文字的窗口!耗时 " & DateDiff("s", dtStart, Now()) _
- & " 秒。", vbSystemModal+vbInformation, WScript.ScriptName
- Else
- Msgbox "找不到含有“" & sTitle & "”文字的窗口!耗时 " & DateDiff("s", dtStart, Now()) _
- & " 秒。", vbSystemModal+vbCritical, WScript.ScriptName
- End If
复制代码
|