View Single Post
 
Old 10-19-2019, 02:13 PM
jpl jpl is offline Windows 7 64bit Office 2010 32bit
Advanced Beginner
 
Join Date: Jan 2016
Location: France
Posts: 33
jpl is on a distinguished road
Default

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
Reply With Quote