the first one wasn't bad, you just need some time after Send('^c') ,
Global $MSWord1 = "Doc1.docx - Word"
Global $MSWord2 = "Doc2.docx - Word"
HotKeySet("{F3}", "copy_paste_word")
HotKeySet("{ESC}", "_Exit")
;**********************************
While 1
Sleep(50)
WEnd
;**********************************
;--------------------------------------------------------------------------------------------------------------------------------
Func _Exit()
Exit
EndFunc
;--------------------------------------------------------------------------------------------------------------------------------
Func copy_paste_word()
Local $hWnd1 = WinGetHandle($MSWord1) ; Retrieves the handle of the Document-1 window.
Local $hWnd2 = WinGetHandle($MSWord2) ; Retrieves the handle of the Document-2 window.
WinActivate($hWnd1) ; * Goes on MS Word Document-1 for text selection
Send('^c') ; Copies the selected text (two or three words) to clipboard.
Sleep(100) ; * Give some time
WinActivate($hWnd2) ; activates MS Word Document-2 to paste text
Send('^v') ; pastes the text from clipboard
Send('{SPACE 3}') ; inserts three spaces after the pasted text
WinActivate($hWnd1) ; Goes back ot MS Word Document-1 for next text selection
EndFunc
;--------------------------------------------------------------------------------------------------------------------------------
however,
what donnyh13 suggested is better because it works without activating the document-2 window
#include <MsgBoxConstants.au3>
#include <Word.au3>
HotKeySet("{F3}", "copy_paste_word")
HotKeySet("{ESC}", "_Exit")
Global $sDocName1 = @ScriptDir & "\Doc1.docx"
Global $sDocName2 = @ScriptDir & "\Doc2.docx"
Global $oDoc1, $oDoc2
; Create application object
Global $oWord = _Word_Create()
If @error Then Exit MsgBox($MB_SYSTEMMODAL, "$oWord", "Error creating a new Word application object." & @CRLF & "@error = " & @error & ", @extended = " & @extended)
; Attach to the document by name
$oDoc1 = _Word_DocOpen($oWord, $sDocName1)
If @error Then Exit MsgBox($MB_SYSTEMMODAL, "@error", "Error opening " & $sDocName1 & @CRLF & "@error = " & @error & ", @extended = " & @extended)
; Attach to the document by name
$oDoc2 = _Word_DocOpen($oWord, $sDocName2)
If @error Then Exit MsgBox($MB_SYSTEMMODAL, "@error", "Error opening " & $sDocName2 & @CRLF & "@error = " & @error & ", @extended = " & @extended)
;**********************************
While 1
Sleep(50)
WEnd
;**********************************
;--------------------------------------------------------------------------------------------------------------------------------
Func _Exit()
Exit
EndFunc ;==>_Exit
;--------------------------------------------------------------------------------------------------------------------------------
Func copy_paste_word()
$oDoc1.ActiveWindow.Selection.Copy ; Copy to clipboard from Document 1
$oDoc2.ActiveWindow.Selection.Paste() ; Paste in Document 2
$oDoc2.ActiveWindow.Selection.InsertAfter(" ") ; Insert 3 spaces in Document 2
EndFunc ;==>copy_paste_word
;--------------------------------------------------------------------------------------------------------------------------------