Copy MS Word-Text between two Words

Get help with using AutoHotkey and its commands and hotkeys
Dossy
Posts: 2
Joined: 18 Oct 2018, 03:17

Copy MS Word-Text between two Words

18 Oct 2018, 05:31

Hey there!

I try to copy text from a MS Word-Document to the Clipboard....but I fail ... can someone help me ?:-)

oword := ComObjActive("Word.Application")

Sleep, 200
Start := oword.Activedocument.Range.find.execute(Findtext:="Offer").End
Sleep, 200
End := oword.Activedocument.Range.find.execute(Findtext:="Order").Start
Sleep, 200
oword.Activedocument.Range.find.execute(%Start%, %End%).text.copy
Sleep, 200


Greetings

Dossy
User avatar
TheDewd
Posts: 1131
Joined: 19 Dec 2013, 11:16
Location: USA

Re: Copy MS Word-Text between two Words

18 Oct 2018, 07:41

Code: Select all

#SingleInstance, Force

m := ComObjMissing()

Try {
	oWord := ComObjActive("Word.Application")

	If (oWord) {
		oWord.Selection.Find.Execute(FindText := "Offer", m, m, m, m, m, 1, 1, 1).Select

		If (oWord.Selection.Text) {
			rngStart := oWord.ActiveDocument.Range(oWord.Selection.Range.End, oWord.Selection.Range.End)
			oWord.Selection.Find.Execute(FindText := "Order", m, m, m, m, m, 1, 1, 1).Select
		}

		If (oWord.Selection.Text) {
			rngEnd := oWord.ActiveDocument.Range(oWord.Selection.Range.Start, oWord.Selection.Range.End)
			oWord.ActiveDocument.Range(rngStart.End, rngEnd.Start).Select
		}

		Clipboard := oWord.Selection.Text
	}
}

MsgBox, % Clipboard

ExitApp

https://autohotkey.com/boards/viewtopic ... 788#p71015
Image Bulldozer - Sokoban inspired game from 1994 recreated in AutoHotkey.

Return to “Ask For Help”

Who is online

Users browsing this forum: Bing [Bot], Mipha and 59 guests