Export (0) Print
Expand All
Expand Minimize

Inserting a Word 2007 Content Control into a Building Block

Office 2007

Office Visual How To

Applies to: 2007 Microsoft Office System, Microsoft Office Word 2007

Overview

Building blocks and content controls are extremely flexible. You can create building blocks that contain content controls, or you can create content controls that use building blocks to present rich content selections to the user. In this video, you learn how to programmatically create a content control, and then how to programmatically add that content control to an entry in a building block gallery.

Code It

The following objects are used in this example:

The following example inserts a content control into the active document, and then adds the content control to the collection of building blocks in the template attached to the active document.

private void InsertContentControlIntoBuildingBlock()
{
  //Variable for the new content control.
  Word.ContentControl objCC;

  objCC = Application.ActiveDocument.
    ContentControls.Add(Word
    .WdContentControlType
    .wdContentControlComboBox,
    ref missing);

  objCC.DropdownListEntries
    .Add("Outstanding", "Outstanding", 1);
  objCC.DropdownListEntries
    .Add("Good", "Good", 2);
  objCC.DropdownListEntries
    .Add("Fair", "Fair", 3);

  //Variables for the building block.
  Word.Template objTemplate;
  Word.BuildingBlock objBB;
  Word.Range objRange;

  objTemplate = (Word.Template)Application
    .ActiveDocument.get_AttachedTemplate();
  objRange = Application.ActiveDocument
    .Paragraphs[1].Range;
  objBB = objTemplate.BuildingBlockEntries
    .Add("OGF Rating Scale",
    Word.WdBuildingBlockTypes.wdTypeCustom1, 
    "Building Blocks", objRange, ref missing,
    Word.WdDocPartInsertOptions
    .wdInsertParagraph);
}
Read It

You can also create content controls that use building blocks to display rich text to the user. For more information about how to do this, see the next video in this series: Filtering the Building Block List in a Word 2007 Content Control.

See It

Video splash screen

Watch the Video

Video Length: 00:03:11

File Size: 3.9 MB WMV

Explore It
Show:
© 2014 Microsoft