Click here to Skip to main content
15,887,596 members
Articles / Productivity Apps and Services / Microsoft Office / Microsoft Word
Tip/Trick

Macro to Change the Color of all Equations in a Word Document

Rate me:
Please Sign up or sign in to vote.
1.00/5 (1 vote)
6 Apr 2019CPOL 5K  
Change the Font Color of all Equations in a Word Document

Introduction

If you have ever written Mathematical or Scientific Documents in Word, you may have wanted to Change the Color and other Properties of all Equations in your Word Document to make them look uniformly. There is no Function to do this in Word other than manually and you can't really use Styles inside the Equation Editor. What I've come up with is a simple Macro in VBA that let's you change Font Colors either by Name or to a RGB Color. You can easily Modify the Macro to fit your Needs

Using the code

Using the code is really simple, just copy it into the VBA Editor in Word (just press Alt+F11 to open it up), modify the color and Run it.

You can use predefined Colors from Microsoft (https://docs.microsoft.com/en-us/office/vba/api/word.wdcolorindex) or custom RGB colors, you just have to change the corresponding Lines as explained in the Code.

VB.NET
Sub Change_Equation_Color()
'Macro to Change the Font Color of all Equations in a Word Document
Dim Eq As OMath
For Each Eq In ActiveDocument.OMaths
Eq.Range.Select
Selection.Font.ColorIndex = wdDarkBlue 'Choose Color here, e.g. wdBlack
'Selection.Font.TextColor.RGB = RGB(255, 0, 255) 'To use RGB color, uncomment this line and comment the one above
Next
End Sub

If you want to Change other Things in all Equations, just customize the code, for example add

VB.NET
Selection.Font.Italic = False

before the "Next" to disable the Italic option for all Equations.

Other Things that you can do with the "Font" Object in VBA are listed here:

https://docs.microsoft.com/en-us/office/vba/api/word.font

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Student
Germany Germany
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions

 
-- There are no messages in this forum --