none
How to use Building Blocks in a template other than Normal.dot RRS feed

  • Question

  • I have a similar issue, where I've saved the building blocks in a .dot file and stored the file in the word startup folder.  I get a run time error message, "requested member of the collection does not exist", when I run a macro to insert the building block in a document though.  Seems like the only way I can get the macro to run is by adding the building blocks to normal.dot.  I'd rather store the BB in a separate template file, so that I'm not making changes to normal.dot.

    Any advise would be appreciated.  Thanks.


    Leesa
    • Split by Cindy Meister MVPModerator Monday, January 10, 2011 7:10 PM split for from answered thread for better visibility: http://social.msdn.microsoft.com/Forums/en-US/worddev/threads
    Monday, January 10, 2011 6:58 PM

Answers

  • Created a new template under the Document Building Blocks folder does the trick. 

     Templates.LoadBuildingBlocks

    For Each template_bb In Templates
            If template_bb.Name = "my_BuildingBlocks.dotx" Then Exit For
        Next

    Templates(template_bb.FullName).BuildingBlockEntries("FirmLogo_LA"). _
        Insert Where:=Selection.Range, RichText:=True


    Leesa
    • Marked as answer by Leesa30 Tuesday, January 11, 2011 9:12 PM
    Tuesday, January 11, 2011 9:12 PM

All replies

  • Split from: split for from answered thread for better visibility: http://social.msdn.microsoft.com/Forums/en-US/worddev/thread/8ffb33d5-a876-49c2-aaf3-22c02257c903/f3dc7dc6-db5c-41eb-a4ed-1e9bc361ac5c

    Hi Leesa

    Could you show us the code you tried?

    Also, Building Block sources aren't necessarily "loaded" prior to the point where you actually use them. This is due to the load time, making it seem that Word is "too slow". Often, your code first needs to explicitly load the building blocks from the template.

    So try something like: Templates.LoadBuildingBlocks


    Cindy Meister, VSTO/Word MVP
    Monday, January 10, 2011 7:14 PM
    Moderator
  • ActiveDocument.AttachedTemplate.BuildingBlockEntries("FirmLogo_LA").Insert where:=Selection.Range, RichText:=True

    I added Templates.LoadBuildingBlocks and still get the same error.  I should point out that my macro and the building blocks are located in the same file.

     


    Leesa
    Monday, January 10, 2011 8:14 PM
  • The template that you stored in the startup folder will not be the .AttachedTemplate

    You should store the Building Block Entries in the template from which the document is created by using File>New and selecting that template.


    Hope this helps.

    Doug Robbins - Word MVP,
    dkr[atsymbol]mvps[dot]org
    Posted via the Community Bridge

    "Leesa30" wrote in message news:4b3860cf-0bbe-47ed-8fe8-c8586c46f1ad@communitybridge.codeplex.com...

    ActiveDocument.AttachedTemplate.BuildingBlockEntries("FirmLogo_LA").Insert where:=Selection.Range, RichText:=True

    I added Templates.LoadBuildingBlocks and still get the same error.  I should point out that my macro and the building blocks are located in the same file.


    Leesa


    Doug Robbins - Word MVP dkr[atsymbol]mvps[dot]org
    Monday, January 10, 2011 10:57 PM
  • There is no normal.dot in any Word application that uses building blocks. The normal template is normal.dotm. If you want a macro to locate a building block in a  particular location then you can address it directly in your macro. If you don't know exactly where it is stored you can search all the available locations where it might be stored. See the section - Insert Autotext Entry with VBA - Word 2007/2010 at http://www.gmayor.com/word_vba_examples.htm



    <Leesa30> wrote in message news:f3dc7dc6-db5c-41eb-a4ed-1e9bc361ac5c@communitybridge.codeplex.com...

    I have a similar issue, where I've saved the building blocks in a .dot file and stored the file in the word startup folder.  I get a run time error message, "requested member of the collection does not exist", when I run a macro to insert the building block in a document though.  Seems like the only way I can get the macro to run is by adding the building blocks to normal.dot.  I'd rather store the BB in a separate template file, so that I'm not making changes to normal.dot.

    Any advise would be appreciated.  Thanks.


    --------------------------------------------------------------------------------
    Leesa


    Graham Mayor - Word MVP
    www.gmayor.com
    Posted via the Communities Bridge
    http://communitybridge.codeplex.com/
    Tuesday, January 11, 2011 8:06 AM
  • Created a new template under the Document Building Blocks folder does the trick. 

     Templates.LoadBuildingBlocks

    For Each template_bb In Templates
            If template_bb.Name = "my_BuildingBlocks.dotx" Then Exit For
        Next

    Templates(template_bb.FullName).BuildingBlockEntries("FirmLogo_LA"). _
        Insert Where:=Selection.Range, RichText:=True


    Leesa
    • Marked as answer by Leesa30 Tuesday, January 11, 2011 9:12 PM
    Tuesday, January 11, 2011 9:12 PM