add powers to a maths equation no.2

The macro below will produce the powers in a maths equation by making the powers size 8 and raising them by 2 points. To do this, put a ‘z’ in front of anything you want to be a power. For anything that you want to be a subscript put a ‘q’ in front of it and it will be lowered by 2 points and made size 8. So to make the following equation:

first insert a fraction from Insert>Equation:

then type (pSOq3)z2 on the top line and (pSOq2)z2 (pOq2) on the bottom line. Then run the macro below. It will also change Cambria Math (sic) font to Arial and get rid of the italics.

Sub MathsEquationsRaisePowersWithZ()

 Selection.Find.ClearFormatting
    Selection.Find.Replacement.ClearFormatting
    With Selection.Find.Replacement.Font
        .Size = 8
        .Superscript = False
        .Subscript = False
        .Position = 1
    End With
    With Selection.Find
        .Text = "([z])([-])"
        .Replacement.Text = "\2"
        .Forward = True
        .Wrap = wdFindContinue
        .Format = True
        .MatchCase = False
        .MatchWholeWord = False
        .MatchAllWordForms = False
        .MatchSoundsLike = False
        .MatchWildcards = True
    End With
    Selection.Find.Execute Replace:=wdReplaceAll
    
    Selection.Find.ClearFormatting
    Selection.Find.Replacement.ClearFormatting
    With Selection.Find.Replacement.Font
        .Size = 8
        .Superscript = False
        .Subscript = False
        .Position = 2
    End With
    With Selection.Find
        .Text = "([z])([0-9])"
        .Replacement.Text = "\2"
        .Forward = True
        .Wrap = wdFindContinue
        .Format = True
        .MatchCase = False
        .MatchWholeWord = False
        .MatchAllWordForms = False
        .MatchSoundsLike = False
        .MatchWildcards = True
    End With
    Selection.Find.Execute Replace:=wdReplaceAll
    
    Selection.Find.ClearFormatting
    Selection.Find.Replacement.ClearFormatting
    With Selection.Find.Replacement.Font
        .Size = 8
        .Superscript = False
        .Subscript = False
        .Position = -2
    End With
    With Selection.Find
        .Text = "([q])([0-9])"
        .Replacement.Text = "\2"
        .Forward = True
        .Wrap = wdFindContinue
        .Format = True
        .MatchCase = False
        .MatchWholeWord = False
        .MatchAllWordForms = False
        .MatchSoundsLike = False
        .MatchWildcards = True
    End With
    Selection.Find.Execute Replace:=wdReplaceAll
      
   For Each equation In ActiveDocument.OMaths
        equation.Range.Font.Italic = False
    Next equation
    
    'Selection.TypeText Text:=" "
    
    For Each equation In ActiveDocument.OMaths
        equation.Range.Font.Name = "Arial"
    Next equation
          
End Sub

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: