0
votes

I am writing a macro in VBA Excel, which is used to do some data processing on a word document. During this, I've changed the font name for the entire document to Times New Roman. But I don't want the same change applied to the 'equation editor' boxes in the document, since their font is "Cambria Math". Changing the font to Times New Roman is resulting into ambiguous data.

1
Which MS Office version as you using?Siddharth Rout
I am using office 2007Kaushik Datye

1 Answers

0
votes

The Equations object changed post 2007. Pre 2007, you could work with those objects by declaring Field objects. For example

UNTESTED

Sub Sample()
    Dim fldEqn As Field

    For Each fldEqn In ActiveDocument.Fields
        If fldEqn.Type = wdFieldEmbed Then
            If InStr(1, fldEqn, "Equation.3") Then
                With fldEqn.Result.Font
                   '
                   '~~> Rest of the code
                   '
                End With
            End If
        End If
    Next oField
End Sub

To work with the Equation Objects from 2007 onwards you have to use the OMaths collection.

You can change the font of all the equations using this code

Sub Sample()
    Dim eqns As OMath

    For Each eqns In ActiveDocument.OMaths
        With eqns.Range.Font
            '
            '~~> Rest of the code
            '
        End With
    Next
End Sub