Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

I'm working on the script trying to create equations in the MS Word from Python. I'm using a pywin32 library to communicate over COM, and further based on the MS developer library and VB examples on the webpage I'm writing to the Word file.

this is my code :

import win32com.client as win32

word = win32.gencache.EnsureDispatch('Word.Application')
word.Visible = True

doc = word.Documents.Add()

objRange = doc.Range(0,0)

oMAC = word.OMathAutoCorrect
oMACEntry = word.OMathAutoCorrect.Entries("\vec")

objRange.InsertAfter("a " + oMACEntry.Value + " b")

objRange22 = doc.OMaths.Add(objRange)
objEq = objRange.OMaths(1)
objEq.BuildUp()

In the link below I can check special symbols which can be entered in the equation http://office.microsoft.com/en-001/word-help/linear-format-equations-and-math-autocorrect-in-word-HA101861025.aspx

However I notice that not all of them works: for example \hat \omega works fine while \vec and \rho throws an exception:

Traceback (most recent call last):
  File "C:/Users/akfaz/PycharmProjects/Tex2Doc/main.py", line 14, in <module>
    oMACEntry = word.OMathAutoCorrect.Entries("\vec")
  File "C:\Python33\lib\site-packages\win32com\gen_py\00020905-0000-0000-C000-000000000046x0x8x5\OMathAutoCorrectEntries.py", line 59, in __call__
    ret = self._oleobj_.InvokeTypes(0, LCID, 1, (9, 0), ((16396, 1),),Index
pywintypes.com_error: (-2147352567, 'Exception occurred.', (0, 'Microsoft Word', 'The requested member of the collection does not exist.', 'wdmain11.chm', 25421, -2146822347), None)

Do You have any clues?

share|improve this question

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.