Microsoft Office Forums

Go Back   Microsoft Office Forums > >

 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
  #5  
Old 10-19-2019, 12:02 PM
jpl jpl is offline VBA and Omath object Windows 7 64bit VBA and Omath object Office 2010 32bit
Advanced Beginner
VBA and Omath object
 
Join Date: Jan 2016
Location: France
Posts: 33
jpl is on a distinguished road
Default

Dans la macro ExampleWriteExpression, on peut éviter l'utilisation de l'instruction Selection.TypeText en utilisant un objet Range (que l'on modifie après chaque utilisation de la méthode Add) à la place de l'objet Selection.
La macro modifiée insère la chaîne Metric + inverse metric - metric à la position courante du curseur dans l'équation.


Les 4 lignes de codes de la modification peuvent être remplacées par une procédure prenant en paramètre un objet Range, et une chaîne représentant le signe + ou - à insérer.


Je ne sais pas si ceci est transposable à votre code.

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)
    
    'Initialisation de l'objet plage  à la position du curseur dans l'équation
    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 = MathTerm.Range
    plage.Collapse (wdCollapseEnd)
    plage.Text = "+"
    plage.Collapse (wdCollapseEnd)


    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 = MathTerm.Range
    plage.Collapse (wdCollapseEnd)
    plage.Text = "-"
    plage.Collapse (wdCollapseEnd)


    Set MathTerm = Equation.Functions.Add(plage, wdOMathFunctionScrSub)
    MathTerm.ScrSub.E.Range.Text = "g"
    MathTerm.ScrSub.Sub.Range = ChrW(&H3BC) & ChrW(&H3BD)
  End Sub
Reply With Quote
 



Similar Threads
Thread Thread Starter Forum Replies Last Post
Variables in Equation using OMath object pooley343 Word VBA 0 01-09-2015 10:26 AM
VBA and Omath object Click an object on a slide, show another object on the same slide. meppley7 PowerPoint 2 04-28-2014 01:44 PM
tool tip for object slain Outlook 0 05-19-2011 06:06 AM
Problem: object library invalid or contains references to object definitions aligahk06 Office 0 08-19-2010 12:29 PM
Could not load this object as this object is not present in your computer k.gaurav Office 0 08-17-2009 09:57 PM

Other Forums: Access Forums

All times are GMT -7. The time now is 07:24 AM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2025, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2025 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft