Printing a List of Building Blocks

Written by Allen Wyatt (last updated January 27, 2018)
This tip applies to Word 2007, 2010, 2013, 2016, 2019, and Word in Microsoft 365


2

Karen would like to print out a list of all the Building Blocks available in Word, but can't seem to discover how to do it. You can print out a list of AutoText entries, but that is only a subset of the larger group of Building Blocks you could have on a system.

There is no built-in capability to print all the Building Blocks on a system, but you can create a macro to access the Building Block information. Building Blocks are stored in templates, with the Building Blocks.dotx template containing all the built-in Building Blocks. Therefore, you need to create a macro that steps through each template that you have open and grabs the building block information from each of them. Consider the following example:

Sub PrintBuildingBlocks()
    Dim oTemplate As Template
    Dim oBBT As BuildingBlockType
    Dim oCat As Category
    Dim oBB As BuildingBlock
    Dim J As Integer
    Dim K As Integer
    Dim L As Integer

    ' Loops through all of the open templates
    For Each oTemplate In Templates
        ' Prints the name of the template
        Selection.TypeText oTemplate.Name & vbCrLf
        For J = 1 To oTemplate.BuildingBlockTypes.Count
            Set oBBT = oTemplate.BuildingBlockTypes(J)
            ' Checks if the building block category has at least one entry
            If oBBT.Categories.Count > 0 Then
                ' Prints the name of the type of building block
                Selection.TypeText vbTab & oBBT.Name & vbCrLf
                For K = 1 To oBBT.Categories.Count
                    Set oCat = oBBT.Categories(K)
                    ' Prints the name of the category of the building block
                    Selection.TypeText vbTab & vbTab & oCat.Name & vbCrLf
                    For L = 1 To oCat.BuildingBlocks.Count
                        Set oBB = oCat.BuildingBlocks.Item(L)
                        ' Prints the name, description, and value
                        Selection.TypeText vbTab & vbTab & vbTab & _
                          "BB " & L & ": " & oBB.Name & vbCrLf
                        Selection.TypeText vbTab & vbTab & vbTab & _
                          "Description: " & oBB.Description & vbCrLf
                        Selection.TypeText vbTab & vbTab & vbTab & _
                          "Value: " & oBB.Value & vbCrLf & vbCrLf
                    Next L
                Next K
            Else
                ' Prints the name of the type of building block AND
                ' mentions that it does not contain any entries
                Selection.TypeText vbTab & oBBT.Name & _
                  " (no entries)" & vbCrLf
            End If
        Next J
    Next oTemplate
End Sub

For the best results, open a brand new document; it is this document into which the macro places the building block information. Before executing the macro, the Building Blocks.dotx should be opened by displaying the Insert tab of the ribbon, then clicking Quick Parts | Building Blocks Organizer. Displaying the Building Blocks Organizer in this manner ensures that Word opens the Building Blocks.dotx template.

When you execute the macro, it steps through each template, through each type of Building Block in the template, through each category in each type, and finally through each Building Block in each category. The name, description, and actual value for each Building Block is printed. This may not give as "pretty" of a result as you might hope because Building Blocks are much more than text—they can be full-fledged programs, as well. This may result in some funky characters in the document created by the macro.

There's also something else interesting to note about this macro. Note that the outside loop steps through each template using a For Each loop. This is rather normal and mundane for working through collections in the Word object model. However, the three nested loops within this outer loop uses a For Next loop because the collections involved (BuildingBlockTypes, Categories, and BuildingBlocks) don't support For Each loops.

Note:

If you would like to know how to use the macros described on this page (or on any other page on the WordTips sites), I've prepared a special page that includes helpful information. Click here to open that special page in a new browser tab.

WordTips is your source for cost-effective Microsoft Word training. (Microsoft Word is the most popular word processing software in the world.) This tip (11096) applies to Microsoft Word 2007, 2010, 2013, 2016, 2019, and Word in Microsoft 365.

Author Bio

Allen Wyatt

With more than 50 non-fiction books and numerous magazine articles to his credit, Allen Wyatt is an internationally recognized author. He is president of Sharon Parq Associates, a computer and publishing services company. ...

MORE FROM ALLEN

Updating Links in Copied Files

When you copy workbooks that contain links, you may be at a loss as to how to update those links. There are a couple of ...

Discover More

Indenting a Paragraph

Normally your text extends from the left margin all the way to the right. If you need to indent a paragraph of your text, ...

Discover More

Deleting Everything Up to a Character Sequence

Sometimes you have too much information in a cell and you need to "pare down" what is there to get to the info you really ...

Discover More

Create Custom Apps with VBA! Discover how to extend the capabilities of Office 2013 (Word, Excel, PowerPoint, Outlook, and Access) with VBA programming, using it for writing macros, automating Office applications, and creating custom applications. Check out Mastering VBA for Office 2013 today!

More WordTips (ribbon)

Moving Building Block Templates

Not all templates are created equal. Word uses two special templates for storing building blocks. If you want to move ...

Discover More

Editing a Building Block Entry

Once you've created a Building Block, you may believe that it is "set in stone" and cannot be changed. Not so! You can ...

Discover More

Extra Spaces after Inserting a Building Block

Building blocks are a great tool for inserting standard information in your documents. It is also possible, however, to ...

Discover More
Subscribe

FREE SERVICE: Get tips like this every week in WordTips, a free productivity newsletter. Enter your address and click "Subscribe."

View most recent newsletter.

Comments

If you would like to add an image to your comment (not an avatar, but an image to help in making the point of your comment), include the characters [{fig}] (all 7 characters, in the sequence shown) in your comment text. You’ll be prompted to upload your image when you submit the comment. Maximum image size is 6Mpixels. Images larger than 600px wide or 1000px tall will be reduced. Up to three images may be included in a comment. All images are subject to review. Commenting privileges may be curtailed if inappropriate images are posted.

What is four less than 7?

2019-04-23 01:18:54

J-Lon

Is there any way to adapt this macro so that it pulls the building blocking entries out of the templates and into a file with a tabular layout (like a spreadsheet)?

Also wondering if it could pull out all the text in the building block and not just the 255 chars.

Trying to get a bunch of building blocks out of a template so I can massage them and then bring them back into a different template using Greg Maxey's Building Blocks Add-On.

Thanks!


2019-01-17 09:35:38

Klein

Hello Allen,

Thank you for this nice code.
I have one problem with the oBB.value. It only copy strings with max length of 255 chars.
Do you see a possibility how to get the whole text of my building blocks?

Thank you and best regards


This Site

Got a version of Word that uses the ribbon interface (Word 2007 or later)? This site is for you! If you use an earlier version of Word, visit our WordTips site focusing on the menu interface.

Videos
Subscribe

FREE SERVICE: Get tips like this every week in WordTips, a free productivity newsletter. Enter your address and click "Subscribe."

(Your e-mail address is not shared with anyone, ever.)

View the most recent newsletter.