Share via


How to: Create a Custom Building Block Gallery

Word Developer Reference

A building block gallery is a collection of building blocks that are of the same type. There are 32 different types of building block collections that you can create (by using the WdBuildingBlockTypes enumeration). Each of these types is a gallery. Microsoft Office Word 2007 provides some of these galleries as built-in building block collections, but most of them are provided so that you can organize your own building blocks. To provide added flexibility with your custom galleries, you can create categories within each gallery to further organize your custom building blocks.

The objects used in this sample are:

Sample

The following example creates a building block gallery that contains three building blocks.

Bb243836.vs_note(en-us,office.12).gif  Note
This example assumes that there are at least three paragraphs in the document.
  Sub CreateBuildingBlockGallery()
    Dim objTemplate As Template
    Dim conType As WdBuildingBlockTypes
    Dim objRange As Range
Set objTemplate = ActiveDocument.AttachedTemplate
conType = wdTypeCustom1

Set objRange = ActiveDocument.Paragraphs(1).Range
objTemplate.BuildingBlockEntries.Add _
    "Heading 1", conType, "Main Headings", objRange

Set objRange = ActiveDocument.Paragraphs(2).Range
objTemplate.BuildingBlockEntries.Add _
    "Heading 2", conType, "Secondary Headings", objRange

Set objRange = ActiveDocument.Paragraphs(3).Range
objTemplate.BuildingBlockEntries.Add _
    "Heading 3", conType, "Tertiary Headings", objRange

End Sub

Additional Resources