Applying Quick Styles and Document Themes in Word 2010
Working with Styles in Microsoft Word: See how to update the Quick Styles and themes in a Microsoft Word 2010 document.
Last modified: May 12, 2011
Applies to: Office 2010 | VBA | Word 2010
Published: May 2011
Provided by: Frank Rice, Microsoft Corporation
In Microsoft Office, themes provide a set of unified design elements for your document through color, fonts, and graphics. Quick Styles change how the different colors, fonts, and effects are combined, and which color, font, and effect dominates the design. In this topic, you programmatically apply different Quick Styles and themes to a document. To complete this task, you must do the following:
In this task, you add programming code that applies different Quick Styles and themes to the text in a document.
To add code to the Visual Basic Editor
Start Word 2010.
On the Developer tab, click Visual Basic to open the Visual Basic Editor.
If you do not see the Developer tab in Word 2010, click the File tab, and then click Options. In the categories pane, click Custom Ribbon, select Developer, and then click OK.
In the Projects pane, click ThisDocument.
Paste or type the following Microsoft Visual Basic for Applications (VBA) code into the module window.
Sub DemoThemeAndQuickStyle() ' Modify this path for your own installation of Microsoft Office: Const themeFolder As String = "C:\Program Files (x86)\Microsoft Office\Document Themes 14\" ' Single step through this code to see the changes as they occur. ' Look at the list of Quick Styles in the user interface ' for more quick style names: ActiveDocument.ApplyQuickStyleSet "Distinctive" ActiveDocument.ApplyQuickStyleSet "Elegant" ActiveDocument.ApplyQuickStyleSet "Manuscript" ' These are just a few of the many available themes: ActiveDocument.ApplyDocumentTheme themeFolder & "Verve.thmx" ActiveDocument.ApplyDocumentTheme themeFolder & "Clarity.thmx" ActiveDocument.ApplyDocumentTheme themeFolder & "Newsprint.thmx" ActiveDocument.ApplyDocumentTheme themeFolder & "Solstice.thmx" End Sub
In this task, you add text to the document and then run the VBA code that applies different styles and themes to the text in a document.
To run the code
In the document, type the following command (without the quotation marks). This adds one paragraph of five sentences to the document.
Drag the Visual Basic Editor window to the right side of your monitor.
Drag the Word window to the left side of your monitor and adjust the windows until you can see them both.
Press F8 to step through the code line-by-line and watch the code interact with the document.