Skip to main content

Find-Text-and-Set-Cursor-Position

Command Description

Find the specified text in a Word document and set the cursor position relative to the first found text

Command Prototype

Word.SetTextPosition(objWord,strText,iStat)

Parameter Description

ParameterRequiredTypeDefaultDescription
objWordTrueexpressionobjWordWord document object
strTextTruestring""The text content to be found in a Word document
iStatTrueenum2Set the cursor position relative to a text

Demo

/************************************Set cursor position after finding text********** **************************** 
Input parameters:
objWord--Word document object
strText--text content to be found in the Word document
iStat--sets the position of the cursor relative to the text
*********************************************************************************/
Dim objWord , sRet
objWord = Word.Open('''C:\Users\Administrator\Desktop\Standardization Implementation Notes.docx''',"xw4131221","",true)
sRet = Word.ReadAll (objWord)
Word.SetTextPosition(objWord,"Company",2)
Word.SetTextPosition(objWord,"表",1)