Share via


Saving a Quick Style Set in Word 2010

Office Quick Note banner

Working with Styles in Microsoft Word: Learn how to save a Quick Styles set template in Microsoft Word 2010.

Applies to: Office 2010 | VBA | Word 2010

In this article
Add the Code to the Visual Basic Editor
Test the Solution
Next Steps

Published:   May 2011

Provided by:    Frank Rice, Microsoft Corporation

Quick Style sets enable you to choose a set of styles that are designed to work together. The colors and formats in a single style set create an attractive and readable document. In this topic, you programmatically apply various styles to the text in a document and then save the document as a Quick Style set template. To complete this task, you must do the following:

  • Add the Code to the Visual Basic Editor

  • Test the Solution

Add the Code to the Visual Basic Editor

In this task, you add programming code that applies various styles to the text in a document and then saves the document as a Quick Styles set template.

To add code to the Visual Basic Editor

  1. Start Word 2010.

  2. On the Developer tab, click Visual Basic to open the Visual Basic Editor.

    Note

    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.

  3. In the Projects pane, click ThisDocument.

  4. Paste or type the following Microsoft Visual Basic for Applications (VBA) code into the module window.

    Sub DemoSaveAsQuickStyleSet()
         Dim theme As OfficeTheme
         Set theme = ActiveDocument.DocumentTheme
    
        ' Modify this path for your own installation of Microsoft Office:
        Const themeFolder As String = "C:\Program Files (x86)\Microsoft Office\Document Themes 14\"
    
        ' Modify the name of the new template to meet your needs:
        Const newTemplateName = "C:\temp\Demo1.dotx"
    
        ' Select one of the available theme color sets:
        theme.ThemeColorScheme.Load themeFolder & "Theme Colors\Adjacency.xml"
    
        ' Select one of the available theme fonts:
        theme.ThemeFontScheme.Load themeFolder & "Theme Fonts\Slipstream.xml"
    
        ' Save the settings as a new quick style set. This actually
        ' creates a new document template, which you can use for
        ' creating future documents.
        ActiveDocument.SaveAsQuickStyleSet newTemplateName
    
        ' Verify that in the new document that this statement creates,
        ' the theme color and font correspond to the options you
        ' set when you created the quick set.
        Documents.Add newTemplateName
    End Sub
    

Test the Solution

In this task, you add text to the document and then step through the VBA code. The code applies different styles and then saves the document as a Quick Styles template.

To run the code

  1. In the document, type the following command (without the quotation marks). This adds five paragraphs of five sentences each to the document.

    "=rand(5,5)"

  2. Drag the Visual Basic Editor window to the right side of your monitor.

  3. Drag the Word window to the left side of your monitor and adjust the windows until you can see them both.

  4. Press F8 to step through the code line-by-line.

  5. Open the folder that you specified in the code to verify that the template was created.

Next Steps