Class BuildingBlocks (Word VBA)

The class BuildingBlocks represents a collection of BuildingBlock objects for a specific building block type and category in a template. To use a BuildingBlocks class variable it first needs to be instantiated, for example


Dim bbs as BuildingBlocks
Set bbs = CustomizationContext.BuildingBlockEntries(1).Category.BuildingBlocks

Add

Creates a new building block and returns a BuildingBlock object.

Add (Name, Range, Description, InsertOptions)


Dim objTemplate As Template 
 
Set objTemplate = Templates(1) 
 
objTemplate.BuildingBlockTypes(wdTypeAutoText) _ 
 .Categories("General").BuildingBlocks _ 
 .Add Name:="New Building Block", _ 
 Range:=Selection.Range

Arguments

The following arguments are required:

Name (String) - Specifies the name of the building block entry. Corresponds to the Name property of the BuildingBlock object.

Range (Range) - Specifies the value of the buildling block entry. Corresponds to the Value property of the BuildingBlock object.

Optional arguments

The following arguments are optional

Description (String) - Specifies the description of the buildling block entry. Corresponds to the Description property of the BuildingBlock object.

InsertOptions (WdDocPartInsertOptions) - Specifies whether the building block entry is inserted as a page, a paragraph, or inline. If omitted, the default value is wdInsertContent. Corresponds to the InsertOptions property for the BuildingBlock object.

Possible return values are wdInsertContent - Inline building block, wdInsertPage - Page-level building block, wdInsertParagraph - Paragraph-level building block.

Count

Returns the number of items in the BuildingBlocks collection.


Dim lngCount As Long
lngCount = CustomizationContext.BuildingBlockEntries(1).Category.BuildingBlocks.Count

Item

Returns a BuildingBlock object that represents the specified item in the collection.

Item (Index)

Index: Specifies a String or Integer that represents the name or ordinal position of the object in the collection.


Dim bbk As BuildingBlock
Set bbk = CustomizationContext.BuildingBlockEntries(1).Category.BuildingBlocks(Index:=1)