Page 1 of 1

COM select text / find text

Posted: 22 May 2018, 02:15
by Johana
Hello!

I am trying to select text inside a Word-document using COM. The problem that I encountered is that I don't know how many lines to select, so something like

Code: Select all

oWord.Selection.MoveDown(5, 3, 9)
will not help me. I am trying to select from row 7 to the END char of page 1. (not the end of page 1 because there's a unwanted empty row).

Question two: I am trying to find a word in Word (with COM) and putting it into a variable.

Using

Code: Select all

oWord.Selection.Find.Execute("My word")
works for the entire document except for the part I want to search. It's inside a textbox.

Help appreicated.

Re: COM select text / find text

Posted: 22 May 2018, 04:02
by Johana
Solved the first part like this:

Code: Select all

oWord.Selection.Goto(1, 2) ; Go to begging of page 2
oWord.Selection.MoveUp(5, 2, 0) ; Move up without selecting, 2 rows
oWord.Selection.HomeKey(6, 1) ; Mark everything from where carat is to begging.
oWord.Selection.MoveDown(5, 4, 1) ; Move down 4