This documentation is archived and is not being maintained.

Creating Content Controls in Word 2010

Office 2010

Office Quick Note banner

Handy Programming Tips for Microsoft Word 2010: Learn how to create content controls in Microsoft Word 2010.

Last modified: May 10, 2011

Applies to: Office 2007 | Office 2010 | VBA | Word 2010

In this article
Add a Standard Module to a Word Document
Add the Code to the Visual Basic Editor
Test the Solution
Next Steps

Published:   May 2011

Provided by:    Frank Rice, Microsoft Corporation

Content controls enable you to design documents and templates. Some characteristics of content controls include data binding to a data source, a user interface that is optimized for controlled input and print, and an ability to restrict users from editing specific parts of a document. In this topic, you programmatically create two simple content controls and set various properties. To complete this task, you must do the following:

In this task, you open a Word 2010 document, open the Visual Basic Editor, and then insert a standard module.

To add a standard module to a Word document

  1. Start Word 2010.

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

    Note 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. On the Insert menu, click Module. This adds Module1 to the Projects pane on the left side of the Visual Basic Editor.

In this task, you add programming code that creates two simple CheckBox content controls and then sets various properties of the controls.

To add code to the Visual Basic Editor

  1. In the Projects pane, click Module1.

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

    Sub CheckedSymbolDemo()
        Dim cc As ContentControl
        Set cc = ActiveDocument.ContentControls.Add(wdContentControlCheckBox)
        cc.Title = "Fancy Check Box"
        cc.SetCheckedSymbol CharacterNumber:=74, Font:="Wingdings"
        cc.SetUncheckedSymbol CharacterNumber:=76, Font:="Wingdings"
        cc.Checked = True
       
        ' Display a plain check box, too.
        Dim cc1 As ContentControl
        Set cc1 = ActiveDocument.ContentControls.Add(wdContentControlCheckBox)
        cc1.Title = "Plain Old Check Box"
        cc1.Checked = True
    End Sub
    
    

In this task, you run the VBA code that creates the controls.

To run the code

  1. On the Developers tab, click Macros, select CheckedSymbolDemo, and then click Run to add two content controls to the document.

  2. Examine the controls and click each one to see the effects. They should look similar to those in Figure 1.

    Figure 1. Running the code creates two content controls

    Running the code creates two content controls
Show: