[python-win32] Unicode trouble

Tim Golden tim.golden at viacom-outdoor.co.uk
Fri Dec 2 11:52:34 CET 2005


[Øyvind]

> I am trying to use the search and replace-function in MS Word. (Office
> 2003, XP and Activestate Python 2.3). It works great until I use
> non-english letters.

> [... ]
>>> objSelection.Find.Execute(en, False, True, False, False, True, True,
1, True, to, 2, False, False, False, False)


> "... The Find What text for a Find All Word 
> Forms search can only contain alphabetic letters"



I think (and it's a guess) that the order of params isn't what
you think it is. Frankly, it looks right, but playing around
a bit with named params is both more readable, and seems to
give the right results. I experimented a bit with your code,
and even my own name (which uses nothing outside standard ASCII)
gave the same error.

The following code seems to work:

<code>
import win32com.client

word = win32com.client.gencache.EnsureDispatch ("Word.Application")
constants = win32com.client.constants

doc = word.Documents.Open ("c:/temp/test.doc")
doc.Content.Find.Execute (
  FindText=u'Kan man gjøre dette?',
  ReplaceWith=u'Nå tryner det skikkelig',
  Replace=constants.wdReplaceAll
)
</code>

TJG

________________________________________________________________________
This e-mail has been scanned for all viruses by Star. The
service is powered by MessageLabs. For more information on a proactive
anti-virus service working around the clock, around the globe, visit:
http://www.star.net.uk
________________________________________________________________________


More information about the Python-win32 mailing list