好像解决了。。。- Const strWindowTitle = "aaaa|bbbb" ' 监控的窗口标题
-
- Do
- Main
- WScript.Sleep 2000
- Loop
-
- Sub Main()
-
- Dim wso, fso
- Dim bFind, o
-
- Set wso = CreateObject("Wscript.Shell")
- Set fso=CreateObject("Scripting.FileSystemObject")
-
-
-
- Do
- For Each o In Split(strWindowTitle,"|")
- 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 '退出循环
- WScript.Sleep 200 '延时0.2 秒
- Loop
-
-
-
-
- '一直检查窗口,直到指定窗口出现
- If bFind Then
-
- '激活窗口
- Call WindowActive(strWindowTitle)
-
- '关闭窗口(发送 Alt + F4)
- wso.SendKeys "(%{F4})"
- '关闭窗口(发送 回车)
- 'wso.sendkeys "{enter}"
-
- Set wso = NoThing
-
- Else
- End If
-
-
-
- End Sub
-
-
-
- '激活窗口
- Sub WindowActive(ByVal strWindowTitle)
- Dim objWord, objTasks
- Set objWord = CreateObject("word.Application")
- Set objTasks = objWord.Tasks
- If objTasks.Exists(strWindowTitle) Then
- objTasks(strWindowTitle).Activate '激活窗口
- objTasks(strWindowTitle).WindowState = 0 '0平常模式、1最大化模式、2最小化模式
- End If
- objWord.Quit
- End Sub
复制代码
|