+ Reply to Thread
Results 1 to 3 of 3

Find and replace of text in math equations

Hybrid View

  1. #1
    Registered User
    Join Date
    09-10-2012
    Location
    NY, NY
    MS-Off Ver
    Excel 2010
    Posts
    13

    Find and replace of text in math equations

    Hi,

    I'm looking to change all text [a-zA-Z] in equations to italics using VBA. I don't want to change anything outside of the equations in equation editor, however.

    Here's my code:
    Sub Chgeqts()
    Dim MathObj As Object
    Dim intPos As Integer
    Dim rngObj As Range
    
        For Each MathObj In ActiveDocument.OMaths
            With MathObj
            Set rngObj = MathObj.Range
            .ConvertToNormalText
               rngObj.Font.Name = "Times New Roman"
                    rngObj.Select
                    With Selection.Find
                       .Text = "[a-zA-Z]"
                       .Replacement.Font.Italic = True
                       .Forward = True
                       .Wrap = wdFindContinue
                       .Format = True
                       .MatchWildcards = True
                       .Execute Replace:=wdReplaceAll
                    End With
             End With
    Next
    End Sub
    This, unfortunately, changes all text to italics, and I can't figure out why...
    Thank you for your help!

  2. #2
    Forum Expert macropod's Avatar
    Join Date
    12-22-2011
    Location
    Canberra, Australia
    MS-Off Ver
    Word, Excel & Powerpoint 2003 & 2010
    Posts
    3,838

    Re: Find and replace of text in math equations

    Try:
    Sub Demo()
    Dim i As Long
    With ActiveDocument
      For i = 1 To .OMaths.Count
        .OMaths(i).Range.Font.Italic = True
      Next
    End With
    End Sub
    Cheers,
    Paul Edstein
    [Fmr MS MVP - Word]

  3. #3
    Registered User
    Join Date
    09-10-2012
    Location
    NY, NY
    MS-Off Ver
    Excel 2010
    Posts
    13

    Re: Find and replace of text in math equations

    Hi,

    I ended up solving this by:
    Public ft As String
    Public MathObj As Object
    Public rngObj As Range
    Sub Chgeqts()
    
    ft = "Aparajita"
    
        For Each MathObj In ActiveDocument.OMaths
            With MathObj
            Set rngObj = MathObj.Range
            .ConvertToNormalText
               rngObj.Font.Name = ft
               Selection.Find.Font.Name = ft
                    With Selection.Find
                       .Text = "[a-zA-Z]"
                       .Replacement.Font.Italic = True
                       .Forward = True
                       .Wrap = wdFindContinue
                       .Format = True
                       .MatchWildcards = True
                       .Execute Replace:=wdReplaceAll
                    End With
             End With
    Next
    Call Timesfont
        Set rngObj = Nothing
        ft = ""
    End Sub
    Function Timesfont()
        For Each MathObj In ActiveDocument.OMaths
                With MathObj
                Set rngObj = MathObj.Range
                rngObj.Font.Name = "Times New Roman"
                End With
            Next
    End Function
    This allows me to differentiate between numbers and letters...as I don't want numbers italicized.

    If you can think of a better way, please let me know...this is a bit of a hack.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Calculating long math equations in Excel
    By JC_LA_1979 in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 06-03-2014, 05:18 PM
  2. Vlookup & Formula with Multiple Math Equations?
    By maverickballa24 in forum Excel Formulas & Functions
    Replies: 0
    Last Post: 11-19-2013, 04:23 PM
  3. help with writing math equations
    By airfrm in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 11-13-2013, 08:38 PM
  4. find in excel replace in word: find/replace text in text boxes and headers
    By dean.rogers in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 04-10-2012, 12:40 PM
  5. Replies: 3
    Last Post: 02-16-2006, 07:00 AM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1