Find.Execute not working with package Win32com
Question: I got a problem that I really can't understand with a Python script I found on
Stackoverflow 2 weeks ago and which worked perfectly until yesterday (with no
changes at all !)

I got a document where I want to find a list of words and replace them with
other words. Here is my code :

    
    
    import win32com.client
    
    word = win32com.client.DispatchEx("Word.Application")
    word.Visible = True
    word.DisplayAlerts = False
    word.Documents.Open(path)
    
    FromTo = {"<#TITLE#>":"The title I want", "<#COMPANY#>":"My Company"}
    
    for From in FromTo.keys():
        word.Selection.Find.Text = From
        word.Selection.Find.Replacement.Text = FromTo[From]
        word.Selection.Find.Execute(Replace=2, Forward=True)
    
    word.ActiveDocument.SaveAs(path)
    

The thing is that the document is opened, the text to find is selected
properly, but nothing happens as the code comes to line
`word.Selection.Find.Execute(Replace=2, Forward=True)`. The document is
normally saved after that, and I got no error message.

Does someone have an idea about why this code doesn't work ? It's quite weird
that the same code worked two weeks ago and doesn't make anything right now.

Thanks for helping me !


Answer: I know this is old, but I was having the same issue and found that if I change
gen_py to xxgen_py in site-packages\win32com (essentially making it unusable)
I no longer have this issue. I'm not sure what is going on, but this was the
only way I could get fin.execute to actually replace the words and not just
highlight.

edit: using the other replacement method in the previous answer worked for me,
keeping gen_py folder.

