I need to change some values ββof custom properties in many files. Here is a sample code - how do I do this for a single file:
import win32com.client
MSWord = win32com.client.Dispatch("Word.Application")
MSWord.Visible = False
doc = MSWord.Documents.Open(file)
doc.CustomDocumentProperties('Some Property').Value = 'Some New Value'
doc.Save()
doc.Close()
MSWord.Quit()
Running the same code for "Excel.Application"(with minor changes - just for it to work) gives an excellent result. However, when I use doc.Save()or doc.SaveAs(same_file)for MSWord, it silently fails. I donβt know why, but the changes are not saved.
Now my workaround is to use SaveAsfor another file, it also works well. But I want to understand why I have such strange behavior for MSWord files and how can I fix this?
. , try/except.
, :)