Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How to use QM's regular expression to replace text in word
#5
Quote:4.VBA:(To manipulate specific words in the entire Microsoft Word document)

Const wdReplaceAll = 2
Set objWord = CreateObject("Word.Application")
objWord.Visible = True
Set objDoc = objWord.Documents.Open("C:\Scripts\Test.doc")
Set objSelection = objWord.Selection
objSelection.Find.Text = "Fabrikam"
objSelection.Find.Forward = TRUE
objSelection.Find.MatchWholeWord = TRUE
objSelection.Find.Replacement.Font.Bold = True
objSelection.Find.Execute ,,,,,,,,,,wdReplaceAll
Macro Find and Replace 4
Code:
Copy      Help
;/exe 1

typelib Word {00020905-0000-0000-C000-000000000046} 8.0
Word.Application app._create
Word.Documents doc=app.Documents
str WordDoc="$desktop$\Scripts\Test.docx"
VARIANT vWordFile=WordDoc.expandpath
doc.Open(vWordFile)
app.Selection.Find.Text = "Fabrikam"
app.Selection.Find.Forward=1
app.Selection.Find.MatchWholeWord=1
app.Selection.Find.Replacement.Font.Bold=1
VARIANT vReplace=Word.wdReplaceAll
app.Selection.Find.Execute(@ @ @ @ @ @ @ @ @ @ vReplace)
app.ActiveDocument.Save
app.ActiveDocument.Close
app.Quit


Messages In This Thread

Forum Jump:


Users browsing this thread: 1 Guest(s)