You want to apply a style in Word and have it automatically insert a predefined block of text, such as a signature, disclaimer, or boilerplate clause. Word does not natively allow a paragraph style to trigger an AutoText or Quick Part insertion when you click it in the Styles gallery. However, you can achieve this behavior by combining a custom style with a macro that runs when the style is applied. This article explains how to set up a style-linked AutoText insertion using a simple VBA macro, including the exact steps to create the style, record the AutoText entry, and assign the macro to the style.
Key Takeaways: Creating a Style That Inserts AutoText on Apply
- Home > Styles > Create a Style: Define a new paragraph style with the formatting you need for the inserted content.
- Insert > Quick Parts > AutoText > Save Selection to AutoText Gallery: Save the block of text you want inserted as an AutoText entry with a unique name.
- Alt+F11 to open VBA editor > Insert Module > Paste macro that applies the style and inserts the AutoText: The macro is the core mechanism that triggers the insertion when the style is applied.
How a Style Can Trigger AutoText Insertion
Word styles are designed to apply formatting attributes such as font, size, spacing, and borders. They do not have a built-in event that runs code or inserts content when you select them from the Styles pane or gallery. To make a style insert AutoText, you must use a macro that intercepts the style application. The macro first applies the style to the current paragraph, then inserts the AutoText entry at the cursor position. This approach requires that you save the desired content as an AutoText entry and create a VBA macro that calls the AutoText insertion. The macro must be stored in the document or a global template so it runs when the style is applied.
Before starting, ensure macros are enabled in your Trust Center settings. Go to File > Options > Trust Center > Trust Center Settings > Macro Settings and select Enable all macros. Also check the box for Trust access to the VBA project object model. This is required for the macro to run automatically.
Steps to Create the Style and AutoText Macro
- Create the AutoText entry
Type the text block you want inserted, for example a legal disclaimer or signature block. Select the entire text. Go to Insert > Quick Parts > AutoText > Save Selection to AutoText Gallery. In the Create New Building Block dialog, type a unique name such as “MyDisclaimer”. Set the Gallery to AutoText. Click OK. - Create the custom style
On the Home tab, click the Styles dialog launcher (the small arrow at the bottom right of the Styles group). Click the New Style button at the bottom of the Styles pane. In the Create New Style from Formatting dialog, type a name such as “Disclaimer Style”. Set the Style type to Paragraph. Configure the formatting you want for the text block. Click OK. - Open the VBA editor
Press Alt+F11 to open the Visual Basic for Applications editor. In the Project Explorer pane, locate your document or the Normal.dotm template. Right-click the project name and choose Insert > Module. A new code module opens. - Write the macro
In the module, paste the following code:Sub ApplyDisclaimerStyle()
Selection.Style = ActiveDocument.Styles("Disclaimer Style")
Application.Templates(_
Loaded:=True).BuildingBlockEntries("MyDisclaimer").Insert _
Where:=Selection.Range, RichText:=True
End Sub
Replace “Disclaimer Style” with your style name and “MyDisclaimer” with your AutoText entry name. Close the VBA editor. - Assign the macro to the style
Word does not allow you to assign a macro directly to a style in the user interface. Instead, add the macro to the Quick Access Toolbar or create a keyboard shortcut. To add to the Quick Access Toolbar, go to File > Options > Quick Access Toolbar. Under Choose commands from, select Macros. Select the macro named ApplyDisclaimerStyle and click Add. Click OK. Now clicking that button on the Quick Access Toolbar applies the style and inserts the AutoText. - Test the macro
Place the cursor in a blank paragraph. Click the macro button on the Quick Access Toolbar. The style should be applied to the paragraph, and the AutoText content should appear at the cursor position.
Limitations and Alternative Approaches
The method above does not make the style itself trigger the macro when you click it in the Styles gallery. The macro must be run manually via a button or keyboard shortcut. If you need the style to run the macro automatically when applied through the gallery, you would need a more advanced event-driven macro that monitors the SelectionChange event and checks whether the style has changed. This is complex and can slow down Word. A simpler alternative is to use a custom keyboard shortcut for the macro. Go to File > Options > Customize Ribbon > Customize next to Keyboard shortcuts. Under Categories, select Macros. Under Macros, select ApplyDisclaimerStyle. Assign a shortcut such as Ctrl+Alt+D. Pressing that shortcut applies the style and inserts the AutoText.
Word Does Not Insert the AutoText When the Style Is Applied via the Gallery
This is expected behavior. The macro only runs when you trigger it explicitly. To make the style insertion appear more integrated, you can hide the original style from the Styles pane and instruct users to use the macro button or shortcut instead. Right-click the style in the Styles pane and choose Modify. Check the box for Add to the Styles gallery but leave Add to the Quick Style list unchecked. This prevents the style from appearing in the Quick Styles list, reducing accidental usage.
The Macro Inserts the AutoText in the Wrong Location
The macro inserts the AutoText at the current Selection.Range. If you want the AutoText to appear at the beginning of the paragraph after the style is applied, change the line to Selection.Paragraphs(1).Range.InsertBefore or use a specific bookmark. For most uses, inserting at the cursor is sufficient.
Macro Does Not Run Because of Security Settings
If the macro does not run, check that macros are enabled. Also ensure the document is saved as a macro-enabled document (.docm) or the macro is stored in the Normal.dotm template. If you use a .docx file, macros will not run. Save your file as Word Macro-Enabled Document (docm).
| Item | Macro-Button Method | Event-Driven Macro Method |
|---|---|---|
| Ease of setup | Simple: one macro, one button or shortcut | Complex: requires event handler and style-change detection |
| User interaction | User clicks a button or presses a shortcut | User applies style normally; macro runs behind the scenes |
| Performance impact | None: macro runs only on demand | Moderate: event handler checks every selection change |
| Reliability | High: macro always runs when triggered | Medium: can conflict with other macros or undo |
| Compatibility | Works in Word 2010 and later | Works in Word 2010 and later but may be blocked by security |
You can now create a Word style that inserts AutoText content on apply by using a macro assigned to a button or keyboard shortcut. This method works reliably for any text block you save as an AutoText entry. For a more automatic experience, explore the event-driven approach but be aware of its complexity and potential performance trade-offs. As an advanced tip, store the macro in a global template (Normal.dotm) so it is available in all documents without re-creating the style each time.