Problems with Python for Windows extensions

Kartic removethis.kartic.krishnamurthy at gmail.com
Sun Sep 4 20:00:40 CEST 2005


Hi,

Invoking Execute as shown below works.. I have no explanation why your 
VB to Py converted code did not work.

wdFindContinue = 1
objSelection.Find.Execute('Contosa', False, True, False, False, True, 
True, wdFindContinue, True, 'Fabrikam', wdReplaceAll, False, False, 
False, False)

This finds 'Contosa' and replaces all occurances with 'Fabricam'.

For a full explanation about the arguments to Execute, look it up in the 
VBA Help.

Thanks,
-Kartic


The Great 'KK' uttered these words on 9/3/2005 11:14 AM:
> 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?
> 



More information about the Python-list mailing list