I am using excel vba to write equations in word. I have it mostly working now, except that the fraction component of the equation is not formatting correctly. I want to have an expression that has a fraction where both numerator and denominator have an exponent. But I can't work it to have the exponents in the correct position. Please help.
I have attempted to use brackets and extra spaces - resulting in either no buildup of the equation object, or strange exponents.
Sub TextToEquation()
Dim appWord as Word.Application
Dim eqText as String
Dim ac as OMathAutoCorrectEntry
Dim eqObj as Word.OMaths
'Create new word application
Set appWord = New Word.Application
With appWord
'Create new word document
.Documents.Add
'Turn Math Autocorrect On
.OMathAutoCorrect.UseOutsideOMath = True
With .Selection
'Write Text
.Text = "x^2 \times x^5/x^3"'Find any math autocorrect and replace with character
For each ac in appWord.OMathAutoCorrect.Entries
If InStr(.text, ac.Name) > 0 then
.text = Replace(.text, ac.name, ac.value)
End If
Next ac
End With
'Add math object
Set eqObj = .OMaths.Add(.Range).OMaths.item(1)
'Build up equation <<< THIS IS WHERE THE BUG LIES
eqObj.BuildUp
eqObj.BuildUp
End With
Note: Actual code is different, but this is the relevant code snippet modified to work independently.