1

I'm wordering if there is a way (directly or using VBA) to get a list of all the building blocks as they appear in the Building Blocks Organizer, that is, the names of the building blocks, the Gallery, the Category, the Template, the Behavior, etc. I don't want to extract auto text parts or anything like that. I just want to be able to get and print the complete list of Bilding Blocks and the rest of the info dispayed in the Building Blocks Organizer.

Thanks a lot! D

Olle Sjögren
  • 5,315
  • 3
  • 31
  • 51
wharf_rat
  • 43
  • 1
  • 7

1 Answers1

5

Building block entries are stored within several Word template files. If you want to iterate over all available building blocks, you must therefore iterate over all loaded Word templates. You can do so using the following macro:

Sub ListBuildingBlocks()

    Dim oTemplate As Template
    Dim oBuildingBlock As BuildingBlock
    Dim i As Integer

    For Each oTemplate In Application.Templates
        For i = 1 To oTemplate.BuildingBlockEntries.Count
            Set oBuildingBlock = oTemplate.BuildingBlockEntries.item(i)
            Debug.Print oBuildingBlock.Name + vbTab _
                + oBuildingBlock.Type.Name + vbTab _
                + oBuildingBlock.Category.Name + vbTab _
                + oTemplate.FullName
        Next
    Next

End Sub
Dirk Vollmar
  • 172,527
  • 53
  • 255
  • 316
  • Hi 0xA3, Thank you very much for your reply. I'm running the code from within Word's Visual Basic editor, and I get no results. How would you tweak the macro to make it write the result in a blank document? Thanks again, D – wharf_rat Mar 04 '13 at 11:52
  • The code sample above prints to the *Immediate Window* of the VBA editor. If you want to write to a new document you need to create the document yourself and write to this document. – Dirk Vollmar Mar 04 '13 at 13:39
  • I did not even know there was such a thing as an imnmedaite window. And it was not even open. That's why I was getting no results. Thank you very much for your help! – wharf_rat Mar 05 '13 at 07:30