VBS向指定窗口粘贴数据

'向指定窗口粘贴数据
Dim WshShell
Dim i
Dim Word
Dim ret
ret=0
'检测窗口
strWindowTitle = "Add new parameter to 64 object(s)" '"新建文本文档.txt - 记事本"
Set objWord = CreateObject("Word.Application")
Set colTasks = objWord.Tasks
If colTasks.Exists(strWindowTitle) Then
ret = 1
MsgBox("发现指定窗口!")
'colTasks(strWindowTitle).Close '将指定窗口关闭
Else 
ret = 0
MsgBox("没有该窗口!")
End If
objWord.Quit
'-----------------------------------------------
If  ret Then  
'设置剪切板
Set Word = CreateObject("Word.Application")
Word.Documents.Add
Word.Selection.Text = "规格"
Word.Selection.Copy
Word.Quit False
'------------------------------------------------
Set WshShell=WScript.CreateObject("WScript.Shell")
WScript.Sleep 1000
WshShell.AppActivate  strWindowTitle   '"Add new parameter to 64 object(s)"
For  i=1 To  1 Step  1
WshShell.SendKeys "^v"
WScript.Sleep 50
WshShell.SendKeys "{enter}" 
WScript.Sleep 700
Next 
msgbox "END!"
Else 
'msgbox "窗口不存在!"
End  If

 

posted @ 2020-01-26 23:32  Hello+World!  阅读(331)  评论(0编辑  收藏  举报