【VBS教程3】:VBS如何激活指定窗口

举个例子:
贴段代码:

on error resume next
dim wsh,ye
set wsh = createobject("wscript.shell")
wsh.run "notepad"
for i=1 to 10
wscript.sleep 700
wsh.appactivate("无标题-记事本")
wsh.sendkeys "^v"
wsh.sendkeys i
wsh.sendkeys "%s"
next

如果上面的appactivate激活的窗口不是在当前光标位置,如何选定该窗口??

方法:加上一句
wsh.sendkeys “{ENTER}”

附上修改后的代码:

on error resume next
dim wsh,ye
set wsh = createobject("wscript.shell")
wsh.run "notepad"
for i=1 to 10
wscript.sleep 700
wsh.appactivate("无标题-记事本")
wsh.sendkeys "{ENTER}"
wsh.sendkeys "^v"
wsh.sendkeys i
wsh.sendkeys "%s"
next

你可能感兴趣的:(代码,vbs)