Creating Content Controls in Word 2010
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
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
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.
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
In the Projects pane, click Module1.
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
On the Developers tab, click Macros, select CheckedSymbolDemo, and then click Run to add two content controls to the document.
Examine the controls and click each one to see the effects. They should look similar to those in Figure 1.