[Tutor] Edit a Word document programmatically CORRECTION Open not open

bob gailer bgailer at gmail.com
Tue Oct 14 20:42:21 CEST 2008


Marc Tompkins wrote:
> On Tue, Oct 14, 2008 at 9:23 AM, URBAN LANDREMAN <ulandreman at msn.com 
> <mailto:ulandreman at msn.com>> wrote:
>
>     Thanks for the suggestion.
>
>     When I ran the slightly modified code:
>     import win32com.client
>     app = win32com.client.Dispatch('Word.Application')
>     docOrig =
>     app.Documents.Open('n:\\MetroPlanners\\2006\\MCHResearchProject.doc')
>     range = docOrig.Content()
>
Try range = docOrig.Range()
>
>     range.Find.Text = "e"
>     range.Find.Replacement.Text = "*"
>     range.Find.Execute()
>     docEditted = doc
>
And note that doc is undefined
>
>     docEditted.SaveAs('n:\\MetroPlanners\\2006\\MCHResearchProjectV2.doc')
>     app.Quit()
>
>
>     I got:
>
>     Traceback (most recent call last):
>       File "N:/SPSS/Python/Examples/MSWord/WordFindAndReplaceV2", line
>     5, in <module>
>         range.Find.Text = "e"
>     AttributeError: 'unicode' object has no attribute 'Find'
>
>
> docOrig.Content() returns you a Unicode object, which isn't the same 
> as a Word document at all.  You're then trying to use methods on that 
> object which aren't supported.  I can't give you specifics without 
> doing a bit of Googling myself, but you probably want a different call 
> on line 4 to give you an object you can work with.
>
>
> -- 
> www.fsrtechnologies.com <http://www.fsrtechnologies.com>
> ------------------------------------------------------------------------
>
> _______________________________________________
> Tutor maillist  -  Tutor at python.org
> http://mail.python.org/mailman/listinfo/tutor
>   


-- 
Bob Gailer
Chapel Hill NC 
919-636-4239

When we take the time to be aware of our feelings and 
needs we have more satisfying interatctions with others.

Nonviolent Communication provides tools for this awareness.

As a coach and trainer I can assist you in learning this process.

What is YOUR biggest relationship challenge?



More information about the Tutor mailing list