MS equation generator

Jan 20 2010 9:20 AM
Dear Developers!

I have a problem, and I don't know how to solve it.

Given an expression i.e.: t_2+mc^3+a^3+b_3

I would like to create a macro that automatically finds these equations and convert them Omath object, like Insert ->Equation -> Professional

by the way, it is not as easy as it seems for me, because there are so many equations in the text (MS WORD 2007) and these tags are covered by "{" and "}" so let me give an example:

"This is a mathematical expression {t_2+mc^3+a^3+b_3} and another one {E=mc^2} and more."


I have started the following:



Sub equation()

Dim list As New VBA.Collection
Dim myrange As range
Dim start_ As Long
Dim end_ As Long
Dim akt_range As range
Dim omath As omath

For i = 1 To ActiveDocument.Characters.Count

If ActiveDocument.Characters(i) = "{" Then
start_ = i - 1

ElseIf ActiveDocument.Characters(i) = "}" Then
end_ = i
Selection.SetRange Start:=start_, End:=end_
Set myrange = Selection.range
list.Add myrange
'MsgBox ("range intems= ") & myrange.Characters.Count
End If

Next i

'MsgBox ("count= ") & list.Count

For i = 1 To list.Count

Set akt_range = list.Item(i)
Set akt_range = akt_range.omaths.Add(akt_range)
Set omath = akt_range.omaths(1)
omath.BuildUp

Next

End Sub





It works fine with the first tag, converts it into Omath obj, but, when I use "Omaths.Add(akt_range)" again, a bad part of the text converted.

Could you help me to solve this problem?

I think the problem is the following... When I converted the first range, the starting end ending position of the second and more ranges have been changed.
(in this code)
but, when I find the first range, and convert it into Omath obj, (the start and end positions are not stored) and find the next range the same problem I have.
I don't know how to go on... pls help


Thank you very much