Skip to main content

Batch-Text-Replacement

Command Description

Replace a specific string in a Word document

Command Prototype

bRet = Word.Replace(objWord,sFind,sReplace,optionArgs)

Parameter Description

ParameterRequiredTypeDefaultDescription
objWordTrueexpressionobjWordWord document object
sFindTruestring""The string to match
sReplaceTruestring""The string to replace
matchCaseNonebooleanNoneWhether to be case sensitive; the default is case-insensitive
matchWholeWordNonebooleanNoneWhether to match whole word only, the default is "no"
matchWildcardsNonebooleanNoneWhether to support wildcard (the default is not to support wildcard)
forwardNonebooleanTrueWhether to find down/forward, the default is "yes"
wrapNoneenum0The method for loop matching after a matching is completed
replaceTypeNoneenum1The method for replacing the content

return

bRet,The variable used to save the output of the command.

Demo

/************************************Text batch replacement************* **************************** 
Command prototype:
Word.Replace(objWord,sFind,sReplace,optionArgs)
Input parameters:
objWord--Word document object
sFind--string to match
sReplace--the string to be replaced
matchCase--is case sensitive
matchWholeWord--is case sensitive
matchWildcards--Whether wildcards are supported
forward--whether to look down/backward
wrap--After matching, the way of loop matching
replaceType--the way to replace the content
Outgoing reference:
bRet -- The result returned after the command is run
*********************************************************************************/
Dim objWord , bRet
objWord = Word.Open('''C:\Users\Administrator\Desktop\Standardization Implementation Notes.docx''',"xw4131221","",true)
bRet = Word.Replace(objWord,"表","biao",{"matchCase":false,"matchWholeWord":false,"matchWildcards":false,"forward":true,"wrap":2,"replaceType":"1"})
TracePrint ($ PrevResult)