Search and replace in new Word 2013 version (15.0.4841) broken
OLD project page for the Python extensions for Windows
Brought to you by:
mhammond
I work with MS Word 2013 V 15.0.4833 (old one) and make python scripts for it.
I use the search and replace command of word as follows:
def replace(rng, old, new): ''' Executes a find and replace in the range ''' rng.Find.Text = old rng.Find.Replacement.Text = new rng.Find.Forward = True rng.Find.Execute(Replace=2)
With the new word version (15.0.4841), on a friends PC, the execute command does not replace anymore. If I run rng.Select()
the word in old
is been selected.
I implemented the same code in VBA as macro in word itself and it is working fine...
Both PCs run Windows 10, using Python 3.4.4, pywin32 V219 installed by pip install pypiwin32
.
Also tried using Python 3.5 and installed pywin32 V220 via the installer exe, but with no difference.
Is there any suggestion how to fix it or is it a problem in the pywin32 implementation?
Nevertheless, you are doing a really great job! Keep going!
I found the solution:
The problem was the bindings of the constants.
I just used
win32com.client.Dispatch("Word.Application")
. But the constants were not available at that moment.Using
win32com.client.gencache.EnsureDispatch("Word.Application")
the constants were loaded and the whole replace worked again.*ticket closed*
Last edit: Cyrill 2016-08-04