Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How to use QM's regular expression to replace text in word
#3
Quote:2.VBA:(Find replacement of uncertain content)

For example, in the above code, find: hi123 hi4568 yshi8 and replace it with: hello
Macro Find and Replace 2
Code:
Copy      Help
;/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


Messages In This Thread

Forum Jump:


Users browsing this thread: 2 Guest(s)