View Single Post
 
Old 06-19-2016, 07:10 AM
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 VBA and Omath object

Bonjour à vous.
I try to write equations by means of macro.
To insert structures into my equations, I use the OMathFunctions. Add method.
My macros work most of the time, except when I use the OmathFunctionText function with the constant wdOMathFunctionText.

Macro QuiMarche makes for what I expect from it:
Code:
Sub QuiMarche()
      Dim monEq As OMath, maFonction As OMathFunction, maPlage As Range
      ActiveDocument.Range.Delete
      Set monEq = ActiveDocument.OMaths.Add(Selection.Range).OMaths(1)
      
      'on insère le radical
      Set maPlage = monEq.Range
      Set maFonction = monEq.Functions.Add(Range:=maPlage, Type:=wdOMathFunctionRad)
      maFonction.Rad.Deg.Range.Text = "3": maFonction.Rad.e.Range.Text = "8"
      
      'on insère la suite
      Set maPlage = maFonction.Range
      maPlage.Collapse direction:=wdCollapseEnd
      maPlage.Text = " est égal à 2."
      Set maFonction = monEq.Functions.Add(Range:=maPlage, Type:=wdOMathFunctionNormalText)
  End Sub
If I modify the last line, the macro emits an error message which I do not understand:

Erreur d'exécution '6219' : Impossible d'appliquer la fonction texte à une sélection.

Code:
Sub QuiNeMarchePas()
      Dim monEq As OMath, maFonction As OMathFunction, maPlage As Range
      ActiveDocument.Range.Delete
      Set monEq = ActiveDocument.OMaths.Add(Selection.Range).OMaths(1)
      
      'on insère le radical
      Set maPlage = monEq.Range
      Set maFonction = monEq.Functions.Add(Range:=maPlage, Type:=wdOMathFunctionRad)
      maFonction.Rad.Deg.Range.Text = "3": maFonction.Rad.e.Range.Text = "8"
      
      'on insère la suite
      Set maPlage = maFonction.Range
      maPlage.Collapse direction:=wdCollapseEnd
      maPlage.Text = "=2"
      Set maFonction = monEq.Functions.Add(Range:=maPlage, Type:=wdOMathFunctionText)
  End Sub
If I neutralize the last line, the macro works.

I have never managed to use the OmathFunctionText function without that error message. In what circumstances is it possible to use this function, and what is its utility?

In French
Je cherche à écrire des équations à l'aide de macros.
Pour insérer des structures dans mes équations, j'utilise la méthode OMathFunctions.Add.
Mes macros fonctionnent la plupart du temps, sauf quand j'utilise la fonction OmathFunctionText avec la constante wdOMathFunctionText.
La macro QuiMarche fait ce que j'en attends :

Si je modifie la dernière ligne, la macro émet un message d'erreur que je ne comprends pas :
Erreur d'exécution '6219' : Impossible d'appliquer la fonction texte à une sélection.
....
Si je neutralise la dernière ligne, la macro fonctionne.

Je n'ai jamais réussi à utiliser la fonction OmathFunctionText sans le même message d'erreur. Dans quelles circonstances est il possible d'utiliser cette fonction, et quelle est son utilité ?
Reply With Quote