03-17-2017, 03:17 PM
Quote:2.VBA:(Find replacement of uncertain content)Macro Find and Replace 2
For example, in the above code, find: hi123 hi4568 yshi8 and replace it with: hello
;/exe 1
str wordList=
;hi123
;hi4568
;yshi8
str wordFind
foreach wordFind wordList
,sub.FindandReplace wordFind "hello"
#sub FindandReplace
function str'searchStr str'replaceStr
typelib Word {00020905-0000-0000-C000-000000000046} 8.0
Word.Application app._getactive
app.Selection.Find.ClearFormatting()
app.Selection.Find.Text = searchStr
app.Selection.Find.Replacement.ClearFormatting()
app.Selection.Find.Replacement.Text = replaceStr
VARIANT vForward=1
VARIANT vWrap=Word.wdFindContinue
VARIANT vReplaceAll=Word.wdReplaceAll
app.Selection.Find.Execute(@ @ @ @ @ @ vForward vWrap @ @ vReplaceAll)
app.ActiveDocument.Save