In the Categories list, choose either “All Commands” or “Macros”, as appropriate. In the list on the right, choose a command or macro. Enter a key combination in.
Last update: October 2019
Applicability: Word 365, 2019, 2016; Windows and MAC OS X operating systems.
Here’s a question from a reader::
I am a teacher and I am using Word 2019 to write important documents. I repeatedly need to change the font and size of my document paragraphs. Is there a way to automate my work with Macros, so i can modify my document paragraph with a one click? I am sure this is going to save me a couple of hours per week, which i’ll gladly invest in other tasks.
Thanks for your question. The key advantage of Macros is that they allow you automate your tasks in Microsoft Office applications. Macros can be either recorded or manually coded using Visual Basic for Applications (VBA). Word ships a Macro recorder that allows you to develop automation scripts without coding. If you are just starting out with automation, this might be a good enough solution. That said, with a little bit of VBA knowledge, you can write efficient and powerful Macros.
Enabling the developer tab in Word
If you don’t see the Developer tab in your Microsoft Word Ribbon, you’ll need to setup your Macro development environment.
Open a new Word document. In case that you would like to work on an existing file, ensure that you have a copy for backup, before making any changes.
Now,go ahead and make the developer menu visible in the Ribbon.
Recording aWord Macro – a practical example
Now, hit the newly added Developer tab.
Go to the Code button group.
Hit the Record Macro button to invoke the Macro recorder function.
Define a meaningful name for your Macro. Note:As the name you provide will be used in the auto created VBA code, Ensure no spaces in the Macro name.
Note:Although it’s possible to assign Macros to buttons , for simplicity we’ll runMacro manually via the View tab or Developer tabs.
Execute the sequence of steps you would like to record. In this case, you’ll record the following steps:
Select a specific paragraph in your document.
Go to the Home tab.
Set the font to Times New Roman.
Set the Font Size to 16.
Center your Text by hitting Ctrl +E.
Once Done, return to the Developer tab and hit Stop Recording.
Now let us take a look at the auto-generated VBA code. Hit Macros and then highlight the AutoFormat Macro and hit Edit.
Close the VBA Editor.
Save your work in a Word Macro enabled template
Hit File, then Save As.
In the Save As dialog right hand side, determine your saving location and provide a meaningful name to your Workbook.
Choose Word Macro Enabled Document as your document type. Note: Your Word document will be saved with the .docm suffix.
Hit the Save Button.
Executing your macro
Open your Word document.
Select the Paragraph you would like to automatically format. Just as an example, here’s the paragraph i chose:
Go to the View tab.
Hit the Macros button.
Select your AutoFormat Macro
Hit Run – this will apply the macro on the selected paragraph.
Voi’la , nice result!
Assigning your Macro to Buttons or keyboard shortcuts
Note: This is an optional step that should be attempted after you have followed the Macro recording tutorial above.
OK, so far we got our Macro basics working. Now it’s time to improve a bit our Macro usability in the Word doc. Let me show you how you can associate your Macro with a quick access button, so you can launch it more easily.
Right click on the Ribbon and select Customize the Quick Access Toolbar.
The Word Options dialog will come up.
In the Choose commands from dropdown, select Macros.
Highlight your Macro and hit the Add>> Button to add a shortcut to your Macro to the Quick Access Toolbar.
Hit the Modify… button to define a suitable icon for your Macro.
Define a Display name for your button.
Hit OK.
Now, you can launch your Macro from the Quick Access Toolbar, just above the Ribbon.
Note: You are able to associate your Word Macro not only with quick access buttons but also with command buttons embedded in your document and specific custom keyboard shortcuts.
Creating Word Macros using VBA
With some simple Visual Basic for Applications coding skills we can edit the macros and write programs to automate various kinds of works using VBA.
Aside Note: FYI – some of the Microsoft Office applications, such as Powerpoint and Outlook, do not have built in macro recorders. Therefore, writing VBA is mandatory for writing Powerpoint macros and automating Outlook.
To edit a macro, click on the Developer tab and select Macros in the code option.
Click on the macro and select Edit.
The Visual Basic for applications editor will open up.
Let’s assume that we want to manually edit the Macro we have recorded in the previous step, so that Word not only set the Size, font and alignment of the paragraph, but also the color.
Setting the color of a section is achieved using the following VBA command:
In our case, we’ll want to set it to a random blue, so we’ll append the following snippet to our Recorded macro:
Here’s how your VBA code should look like:
In the VBA Editor hit File and then Save.
Back to your document, run your Macro on a paragraph and observe the font color change.
Voi’la!
Useful Word Macro examples
Since publishing this tutorial, many readers asked for more in depth examples of Word Macros. So here we go with the first batch.
Create and Save New Document
Note: When creating new documents, you are able to specify the template (.dotm/.dotx files) you would like to use. Templates are typically stored at: C:Users<your_user_name>AppDataRoamingMicrosoftTemplates
Open a document
Closing one/all open documents
Inserting header and footer
This code sets the header and footer of your Word document first page.
Additional Word Macro ideas
Here are a few more ideas which we’ll be posting in the upcoming future.
Find and Replace (Execute Method)
Insert a paragraph (before and after a selection)
Printing documents programatically
Working with tables
This concludes our tutorial for today. As you just saw, there is a lot to be done with the Word macro recorder and VBA Macros in Word. In case you are looking for more specific help that goes beyond the scope of this tutorial, kindly contact us via our contact form.
Version note: This article was originally written for Word 97 and 2000 and later updated for Word 2002 and 2003; while I have added some instructions for Word 2007 and above, much of the content is more applicable to Word 2003 and earlier.
In some cases, Word automatically converts text you type into fraction characters. Unless you have disabled the feature on the AutoFormat As You Type tab of AutoCorrect Options, whenever you type 1/4, 1/2, or 3/4, Word substitutes the ¼, ½, or ¾ font character. These three characters are found in virtually all fonts, so this feature works reliably. Users often ask whether it is possible to get Word to “create” other fractions in a similar format. Well, yes and no. This article discusses several approaches to creating fractions:
Font characters
There are several ways to create fractions in Word, but only one of them will produce fractions in the same style as ¼, ½, and ¾. Luckily, if what you need fractions for is recipes, this way will suffice. As you can see from the screen shot below, many fonts include the characters for ⅓, ⅔, ⅛, ⅜, ⅝, and ⅞. These, along with ¼, ½, and ¾, should be all you need for typing most recipes.
The Symbol dialog
As shown above, these characters appear in the Number Forms subset of Unicode fonts such as Times New Roman, Arial, Courier New, Calibri, and Cambria. You can insert them from the Symbol dialog in Word 97 and above. To open the Symbol dialog:
Word 2003 and earlier: Choose Symbol… from the Insert menu. Note that the most recently used symbols are available without scrolling.
Word 2007 and above: On the Insert tab of the Ribbon, in the Symbols group, click Symbol, then More Symbols… Recently used symbols are shown in the Insert | Symbols | Symbol palette as well as in the dialog.
In Word 2002 and above, you can also insert them using the shortcut keys shown (such as 2153, Alt+X for ⅓) or shortcut keys that you assign. In Word for Mac, you need a macro to insert Unicode characters. You can also assign keyboard shortcuts to them.
Note for Mac users: Don’t expect to see a display like the one above in Word for the Mac. Although many Mac fonts contain at least the ¼, ½, and ¾ fractions, the MacRoman Character Set does not contain them, so there are no built-in keystrokes for the characters, and the Symbol dialog in Word won’t show them to you because it is capable of showing only the characters present in the MacRoman character set. You have to look such characters up in the Character Palette (available only if you have OS X). You have to display the Unicode keyboard (and get it to work…), then enter the character in hexadecimal. The fraction fonts mentioned below may be the only way you can access fraction glyphs; if you can’t justify purchase of special fonts, you will need to rely on one of the alternative methods described below.
If you want these fractions to behave the way ¼, ½, and ¾ do, however, you will need to create AutoCorrect entries from them (see “Exploiting AutoCorrect” for instructions on creating AutoCorrect entries). The easiest way to do this, of course, is to create AutoCorrect entries to replace 1/3, 2/3, etc., with the equivalent font characters. That is what most users will do. But users sometimes type dates in M/d or d/M format and don’t want the date for January 2 (or February 1) turned into ½. They therefore disable the AutoFormat As You Type feature to “Replace fractions (1/2) with fraction character (½).” If you are one of those users, then choose different trigger text for your AutoCorrect entries. You could, for example, use 1;3 instead of 1/3. Once you have set up AutoCorrect entries for all six of these extra fractions, you’ll be all set to type recipes.
In addition to the fraction glyphs available in most Unicode fonts, you can purchase fonts that contain only fractions. For example, Adobe sells PostScript fraction fonts to match its New Century Schoolbook and Helvetica fonts. To use these, however, you would have to change fonts and insert the fraction characters using the Symbol dialog or a keyboard chart.
EQ fields
The most universally useful way to create ad hoc fractions is with the EQ (Equation) field using the f switch. This creates a fraction with a horizontal line between the numerator and the denominator. Here’s how to do it:
Place the insertion point where you want the fraction to appear.
Press Ctrl+F9 to insert field braces.
Between the field braces, type the following:
EQ F(a,b)
where a and b are the numerator and denominator of the fraction. For example, if you want to create the fraction 1/16, the field would look like this:
{ EQ F(1,16) }
With the insertion point in the field, press Shift+F9. This gives the following result:
For consistency, it is best not to mix fractions created this way with built-in font characters that use diagonal separators. In a document with varied fractions, use EQ fields even for ¼, ½, and so on so that all the fractions will be uniform.
Note that you are not limited to numbers in EQ fields. If you want to create fractions using words, you can do that, too. Suppose you wanted to represent a financial ratio such as the “acid test” (“quick ratio”):
To achieve this, you would create this field:
{ EQ f (Current assets – Inventory,Current liabilities) }
By default, the EQ f field centers text above and below the division line, and the alignment switches available to some other EQ fields do not work for fractions. Text can be aligned manually, however, by adding spaces to the numerator or denominator as required.
Formatted font characters
For very large or unusual fractions, such as 1/10,000 or 23/250, an EQ field or Equation Editor object, which uses a horizontal separator, is appropriate and satisfactory. But for most common fractions, such as 1/6 or 1/9, users usually want what is called a “shilling” fraction, that is, one with a slanted separator, like the built-in ¼, ½, and ¾ font characters. There is no built-in way to create these, but you can simulate them with a little work. Here’s how:
Type a fraction such as 1/6; instead of the / (forward slash, solidus, virgule) character from your keyboard, you’ll probably want to use the fraction slash or “division slash.” You can find this in the Mathematical Operators subset (glyph 2215) in Unicode fonts or as character 164 in the Symbol font. It is longer and more nearly horizontal and therefore works better for this type of fraction.
Select the numerator and format it as Superscript (Ctrl+Shift+= or check the box for Superscript in the Font dialog).
Select the denominator and format it as Subscript (Ctrl+= or check the box for Subscript in the Font dialog).
Fractions created in this way may need some tweaking to look their best (experiment with the Spacing and Position settings on the Character Spacing tab of the Font dialog). If you’ll be using specific ones frequently, you’ll want to save them as AutoCorrect entries. Also, it is best not to call attention to their failings by mixing them with the built-in font characters. If you will be using this method to create fractions for 1/6 and 1/9, say, do it for 1/4, 1/8, and so on as well so that all the fractions in your document will be uniform.
Using a macro
Former Word MVP Steve Hudson has written a macro that formats characters automatically. It is suitable for use after the text has been created, to automatically format all of the fractions found in document. You can get ithere.
Macros have also been provided byGraham Mayor andGreg Maxey. If you don’t know what to do with these macros, see Graham’s “Idiots’ Guide to Installing Macros.”
Equation editors
All of the methods above are aimed at creating fairly simple fractions, with a single numerator and denominator. At the other end of the spectrum, if you need to create complex mathematical formulas such as the one below, you need heavy-duty tools.
Word 2003 and earlier
Once Word’s Equation Editor is installed (see note below), you can use Insert | Object | Microsoft Equation 3.0 to insert an equation object. If you’ll be doing a lot of this, you’ll want to add an Equation Editor toolbar button. OpenTools | Customize and select the Commands tab. In the Insert category, scroll the Commands list till you find Equation Editor. Select the command with your mouse and drag it to a toolbar (or the Insert menu). (For more detailed information on adding buttons to a toolbar or menu, see “Customizing Toolbars” or “Customizing Menus.”
When you start the Equation Editor, its toolbar will be displayed:
The Equation toolbar
You can select the fraction type you need from the “Fraction and radical templates” palette and then insert numbers in the spaces provided. You can also, using the other tools on the toolbar, create complex formulas such as the one in the example above. The Equation Editor applet has its own Help file, and you can also findhelpful tips at the website of Design Science, which supplies the application to Microsoft.
Note: Equation Editor (Microsoft Equation 3.0) is supplied with all versions of Word but is not installed by default (in the Typical install), so you may need to rerun Setup to install it. To do this, go to Control Panel | Add/Remove Programs, select Microsoft Office, and click the Change button. In the first page, select “Add or Remove Features.” On the next page, expand “Office Tools.” Select Equation Editor and set it to “Run from My Computer.” Click the Update button, and insert the Office CD when prompted. On the Mac, look on your Office CD for the application.
Word 2007 and above
Recent versions of Word have a built-in Equation Editor created by Microsoft. On the Insert tab of the Ribbon, in the Symbols group, click Equation. There is a gallery of sample equations, but you can start from scratch with Insert New Equation. This will cause the contextual Equation Tools | Design tab to be displayed. The Ribbon has a palette of symbols, plus templates for various constructs, including fractions. There are also Math AutoCorrect shortcuts that can be used to create equations from the keyboard. For more information on the use of the new equation editor, seethis article.
Helpful Hint: You don't have to go through Insert | Symbols | Equation | Insert New Equation to insert a new blank equation; there is a keyboard shortcut for this: Alt+= (that is, the Alt and = [equals] keys pressed simultaneously).
Note: If you prefer to continue to use Microsoft Equation 3.0, it is still available in Word 2007 and above, although it is “not supported” in Word 2013 and 2016 (it may still be satisfactory for simple fractions but should not be relied on for complex equations). On the Insert tab of the Ribbon, in the Text group, click Object and select Object from the menu. In the list on the Create New tab, select Microsoft Equation 3.0.
MathType
If you need more features than either of Word’s equation editors offers, you can also download atrial version of Design Science’s MathType, of which Microsoft Equation 3.0 is a cut-down version. If you decide not to purchase MathType at the end of the trial period, it will degrade into MathType Lite, a souped-up version of Microsoft Equation 3.0; you’ll still be able to edit the equations you created with MathType, and you’ll continue to have access to the full set of MathType fonts and symbols.
Fractions in running text
Whenever you insert a fraction that is not a font character, whether you use an EQ field or a combination of superscript and subscript formatting, it is likely that your line spacing will be expanded to compensate for the extra height. If you do not want this to happen, you have two options:
You can set the line spacing to an exact amount (Exactly under Line Spacing in the Paragraph dialog).
You can enable the Compatibility Option for “Don’t add extra space for raised/lowered characters.” This setting will affect only cases where you have raised or lowered your superscript/subscript characters.
Word 2003 and earlier: This setting is on the Compatibility tab of Tools | Options.
Word 2007: Click Office Button, then Word Options. Select the Advanced tab. The Layout Options are at the bottom.
Word 2010: On the File menu, click Options. Select the Advanced tab. The Layout Options are at the bottom.
Word 2013 and above: This option is not available.
For most Equation Editor objects and for text “fractions” such as the Acid Test example above, it is preferable to “display” the text by putting it in a separate, centered paragraph (as has been done in this article).
Challenges for displayed equations
“Displaying” equations is a challenge when using the Microsoft equation editor in Word 2007 and above: If the paragraph that contains the (new) equation editor object also contains one or more characters of regular text, Word automatically changes the equation from “display” to “inline.” That reduces the font size of fractions and forces the limits of integrals and sums to the right of the symbol instead of above and below.
Even if you don't have any regular text in the equation itself, you may need an equation number at the right margin. There are two suggested solutions for this problem:
Put the equation and equation number in separate cells of a single-row table with two or three columns. This approach also solves problems with cross-references, which will repeat the entire equation if the equation and number are in the same paragraph.
There is actually a built-in feature allowing you to preface the equation number with # (as described here). This automatically puts the equation number at the right margin. But this generates its own problems, as described by my fellow Word MVP Jay Freedman:
There is a significant problem in Word’s implementation of this feature: It’s difficult to use such an equation number in a reference. The cross-reference dialog doesn’t see it at all, insisting that the equation must be captioned in order to refer to it. A clumsy workaround is to add a bookmark manually around the equation number in the EE box, and make the cross-reference point to the bookmark. Unfortunately, if the equation number includes the last character in the EE box, then the cross-reference will include the internal code for an EE object, so it will show its own EE box. That could be avoided by adding a space following the equation number and not including that space in the bookmark—just something else to forget to do. If I were writing a long math paper or dissertation, I’d be disgusted at the choice between this and an AutoText of a table.
By “AutoText of a table,” Jay is referring to the first solution mentioned. You can create a single-row table with a dummy equation and equation number and save it as an AutoText entry for ease of insertion.