Nouvelle version
Code:
Sub ExampleWriteExpression()
'insertion point should be in equation. Metric + inverse metric - metric inserted
Dim Equation As OMath
Dim MathTerm As OMathFunction
Dim plage As Range
' If Selection.OMaths.Count <> 1 Then ExpanderFatalError ("Cursor must be in an equation.")
Set Equation = Selection.OMaths(1)
Set plage = Selection.Range
Set MathTerm = Equation.Functions.Add(plage, wdOMathFunctionScrSub)
MathTerm.ScrSub.E.Range.Text = "g"
MathTerm.ScrSub.Sub.Range = ChrW(&H3BC) & ChrW(&H3BD)
'remplace "Selection.TypeText"
Set plage = Insere(MathTerm.Range, "+")
Set MathTerm = Equation.Functions.Add(plage, wdOMathFunctionScrSup)
MathTerm.ScrSup.E.Range = "g"
MathTerm.ScrSup.Sup.Range = ChrW(&H3BC) & ChrW(&H3BD)
'remplace "Selection.TypeText"
Set plage = Insere(MathTerm.Range, "-")
Set MathTerm = Equation.Functions.Add(plage, wdOMathFunctionScrSub)
MathTerm.ScrSub.E.Range.Text = "g"
MathTerm.ScrSub.Sub.Range = ChrW(&H3BC) & ChrW(&H3BD)
End Sub
Function Insere(plage As Range, signe As String) As Range
plage.Collapse (wdCollapseEnd)
plage.Text = signe
plage.Collapse (wdCollapseEnd)
Set Insere = plage
End Function