K
KK
the code below is taken from M$ technet as an example on using vb
script to do a replace all in word:
Const wdReplaceAll = 2
Set objWord = CreateObject("Word.Application")
objWord.Visible = True
Set objDoc =
objWord.Documents.Open("K:\Development\Fabricbase\prod\Test.doc")
Set objSelection = objWord.Selection
objSelection.Find.Text = "Contoso"
objSelection.Find.Forward = True
objSelection.Find.MatchWholeWord = True
objSelection.Find.Replacement.Text = "Fabrikam"
objSelection.Find.Execute ,,,,,,,,,,wdReplaceAll
I did a rewrite and made it pythonic:
from win32com.client import *
wdReplaceAll = 2
objWord = Dispatch("Word.Application")
objWord.Visible = True
objDoc =
objWord.Documents.Open("K:\Development\Fabricbase\prod\Test.doc")
objSelection = objWord.Selection
objSelection.Find.Text = "Contoso"
objSelection.Find.Forward = True
objSelection.Find.MatchWholeWord = True
objSelection.Find.Replacement.Text = "Fabrikam"
objSelection.Find.Execute (Replace = wdReplaceAll)
However, the document juz loaded up in word but no action was taken. I
am using Word 2003. Any ideas?
script to do a replace all in word:
Const wdReplaceAll = 2
Set objWord = CreateObject("Word.Application")
objWord.Visible = True
Set objDoc =
objWord.Documents.Open("K:\Development\Fabricbase\prod\Test.doc")
Set objSelection = objWord.Selection
objSelection.Find.Text = "Contoso"
objSelection.Find.Forward = True
objSelection.Find.MatchWholeWord = True
objSelection.Find.Replacement.Text = "Fabrikam"
objSelection.Find.Execute ,,,,,,,,,,wdReplaceAll
I did a rewrite and made it pythonic:
from win32com.client import *
wdReplaceAll = 2
objWord = Dispatch("Word.Application")
objWord.Visible = True
objDoc =
objWord.Documents.Open("K:\Development\Fabricbase\prod\Test.doc")
objSelection = objWord.Selection
objSelection.Find.Text = "Contoso"
objSelection.Find.Forward = True
objSelection.Find.MatchWholeWord = True
objSelection.Find.Replacement.Text = "Fabrikam"
objSelection.Find.Execute (Replace = wdReplaceAll)
However, the document juz loaded up in word but no action was taken. I
am using Word 2003. Any ideas?