Many thanks, Wade,

I'll have to see whether I did that or not. I came up with a workaround
which is burried now in a package.

I suppose I will have to have a look into the whole thing anyway, because I
changed my OS to W2k. Since then Winword behaves differently: Despite the
fact that I set Visible to 1 it is not visible. It is only visible in the
process list of the task manager (well, that's also a kind of visibility
:-)). Unfortunately it remains there and has to be killed!

Anyway - man thanks again!

Cheers
Franz

> -----Ursprüngliche Nachricht-----
> Von: [EMAIL PROTECTED]
> [mailto:[EMAIL PROTECTED]]Im Auftrag von Wade
> Leftwich
> Gesendet: Samstag, 04. August 2001 12:57
> An: [EMAIL PROTECTED]; Activepython@Listserv. Activestate. Com
> Betreff: RE: Automating Word 9.0 ("Python Programming on Win32"): Cannot
> replace text
>
>
> Have you made sure your wordSel covers the entire document? This
> works from
> a prompt:
>
> from win32com.client import Dispatch
> wapp = Dispatch('Word.Application')
> doc = wapp.Documents.Open('doc_containing_foo.doc')
> wapp.Visible = 1
> sel = wapp.Selection
> sel.WholeStory()
> f = sel.Find
> f.Text = 'foo'
> f.Execute() # if successful, returns 1 and only 'foo' will be highlighted
> sel.Range.Text = 'bar'
>
>
> I also tried setting f.Replacement.Text and doing
> f.Execute(Replace=2), but
> that did
> not make the change, though it DID return 1 and highlight the text to be
> found.
>
>
> Wade Leftwich
> Ithaca, NY
>
>
>
> > -----Original Message-----
> > From: [EMAIL PROTECTED]
> > [mailto:[EMAIL PROTECTED]]On Behalf Of F.
> > GEIGER
> > Sent: Saturday, August 04, 2001 5:18 AM
> > To: Activepython@Listserv. Activestate. Com
> > Subject: Automating Word 9.0 ("Python Programming on Win32"): Cannot
> > replace text
> >
> >
> > Hi all,
> >
> > I created a Word template, which contains a marker, that has to
> > be replaced
> > by some generated text (to be precise: it's a table, where one
> > cell contains
> > the marker text '__CONTENTS__'). I use easyword.py from "ppw32" to wrap
> > word, the only substantial change I did was to rename the class
> to MSWord.
> >
> > So I added a method replacetText(self, old, new):
> >
> >     def replaceText(self, old, new):
> >         f = self.wordSel.Find
> >         f.ClearFormatting()
> >         f.Text = old
> >         f.Replacement.ClearFormatting()
> >         f.Replacement.Text = new
> >         f.Execute(Replace=2, Forward=-1, Wrap=2)
> >         #                 ^           ^       ^...wdFindContinue
> >         #                 |           |...True
> >         #                 |...wdReplaceAll
> >         return
> >
> >
> > The test driver is:
> >
> > def test():
> >     import os
> >     from time import sleep
> >
> >     dirName = '%s\\' % os.getcwd()
> >     w = MSWord(dirName + 'ExTract.dot')
> >     w.show()
> >
> >     w.replaceText('__CONTENTS__', 'Blah blah blah')
> >
> > #    sleep(5)
> > #    w.close()
> >
> >     return
> >
> >
> > When executing this, word starts up, loads the template, and selects
> > '__CONTENTS__'. Then nothing else happens. Especially,
> '__CONTENTS__' does
> > not get replaced with "Blah blah blah".
> >
> > So I tried to do it from within Word, which works.
> >
> > So I tried to do it from within MSVB, which works too:
> >
> > Private Sub cbDoIt_Click()
> > Dim Word As Word.Application
> >
> >    Set Word = CreateObject("Word.Application")
> >
> >    Word.Visible = True
> >
> >    Word.Documents.Add "D:\\PyFL\\MSOffice\\exTract.dot"
> >
> >    Selection.Find.ClearFormatting
> >    Selection.Find.Text = "__CONTENTS__"
> >    Selection.Find.Replacement.ClearFormatting
> >    Selection.Find.Replacement.Text = "Blah blah blah"
> >    Selection.Find.Execute Replace:=2, Forward:=-1, Wrap:=2
> >
> > End Sub
> >
> >
> > As I use ActivePython 2.0 on a NT4.0Svr/SP6 I tried 2.1.1.212
> on an other
> > machine (NT4.0Svr/SP6). Does not work either.
> >
> > Does anybody see, what I forgot to do/call to make it work from within
> > Python too?
> >
> >
> > Best regards
> > Franz GEIGER
> >
> >
> > --------------------------------------------------------
> > DATEC Datentechnik GmbH
> >     Software Development
> >     Retrieval Computing
> > A-6890 LUSTENAU, Schmiedgasse 7
> > Tel +43 5577 630 04-0
> > Fax +43 5577 630 04-40
> > Mobile
> >     +43 664 214 57 43
> > E-Mail
> >     [EMAIL PROTECTED]
> > WWW www.datec.at (in Partnerschaft mit Amazon.de)
> >
> >
> > _______________________________________________
> > ActivePython mailing list
> > [EMAIL PROTECTED]
> > http://listserv.ActiveState.com/mailman/listinfo/activepython
> >
>
> _______________________________________________
> ActivePython mailing list
> [EMAIL PROTECTED]
> http://listserv.ActiveState.com/mailman/listinfo/activepython
>

_______________________________________________
ActivePython mailing list
[EMAIL PROTECTED]
http://listserv.ActiveState.com/mailman/listinfo/activepython

Reply via email to