Excel/Word Equations using oMath.BuildUp method?

Nikola

New Member
Joined
Nov 18, 2013
Messages
3
I am trying to automate process of generating Equations in Microsoft Word 2010 using VBA and inserting those into Excel since it doesnt support oMath object. Problem lies in oMath.BuildUp method. It doesnt interpret stuff like \sqrt, \times, \delta in the same way that it is interpreted when entered by hand.
For example entering code Celsius = \sqrt(x+y) + sin(5/9 \times (Fahrenheit – 23 (\delta)^2)) into Equation will give this result http://i43.tinypic.com/10xc7zp.jpg which is fine.
But when using macro VBA or recording macro this Method is not working as it should be and it gives result like this: http://i42.tinypic.com/29c5geg.png. Stuff like \sqrt, \times, \delta is ignored. Why? Here is macro that I used to generate second picture.
Code:
Sub genEQ()
Dim objRange As Range
Dim objEq As OMath
Set objRange = Selection.Range
objRange.Text = "Celsius = \sqrt(x+y) + sin(5/9 \times (Fahrenheit – 23 (\delta)^2))"
Set objRange = Selection.OMaths.Add(objRange)
Set objEq = objRange.OMaths(1)
objEq.BuildUp
End Sub

I feel this might be a bug :(
 

Excel Facts

How can you automate Excel?
Press Alt+F11 from Windows Excel to open the Visual Basic for Applications (VBA) editor.
It seems that BuildUp doesn't AutoCorrect:

Code:
Sub genEQ()
    Dim objRange As Range
    Dim objEq As OMath
    Dim AC As OMathAutoCorrectEntry
    Application.OMathAutoCorrect.UseOutsideOMath = True
    Set objRange = Selection.Range
    objRange.Text = "Celsius = \sqrt(x+y) + sin(5/9 \times(Fahrenheit – 23 (\delta)^2))"
    For Each AC In Application.OMathAutoCorrect.Entries
        With objRange
            If InStr(.Text, AC.Name) > 0 Then
                .Text = Replace(.Text, AC.Name, AC.Value)
            End If
        End With
    Next AC
    Set objRange = Selection.OMaths.Add(objRange)
    Set objEq = objRange.OMaths(1)
    objEq.BuildUp
End Sub
 
Upvote 0
I just want to say "Thanks!" I'm using MS Word with VBA and this was just what I needed! I was getting frustrated. It works so beautifully. I modified it to be a function that you can use right in line with a string entry... ex. selection.typetext text: = "this is an equation" & build_up(equation_string) & " that looks awesome."

Here's my code:
Function build_up(eq_ As String) As String
Dim objRange As Range
Dim objEq As OMath
Dim AC As OMathAutoCorrectEntry
Application.OMathAutoCorrect.UseOutsideOMath = True
Set objRange = Selection.Range
objRange.Text = eq_
For Each AC In Application.OMathAutoCorrect.Entries
With objRange
If InStr(.Text, AC.Name) > 0 Then
.Text = Replace(.Text, AC.Name, AC.Value)
End If
End With
Next AC
Set objRange = Selection.OMaths.Add(objRange)
Set objEq = objRange.OMaths(1)
objEq.BuildUp
build_up = "" 'just a dummy value
End Function
 
Upvote 0

Forum statistics

Threads
1,223,574
Messages
6,173,145
Members
452,502
Latest member
PQCurious

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top