"KK" <[EMAIL PROTECTED]> schrieb im Newsbeitrag news:[EMAIL PROTECTED] | 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?
KK, Your example seemed to work fine for me (Python2.4, Pythonwin build 204, Word 2003) One thing: since you say your document loads up fine I don't know if it is just a typo, but make sure you follow the rules of backslash literals in path names. In other words: "K:\Development\Fabricbase\prod\Test.doc" should read either r"K:\Development\Fabricbase\prod\Test.doc" (note the leading r for raw string or "K:\\Development\\Fabricbase\\prod\\Test.doc" or "K:/Development/Fabricbase/prod/Test.doc" -- Vincent Wehren -- http://mail.python.org/mailman/listinfo/python-list