LoadBuildingBlocks in Word Document_New and Document_Open very slow

Lauro Colasanti 121 Reputation points
2023-04-01T09:10:29.6866667+00:00

Hi,

I want that some Word documents would be based on quite a complex Word template called MyMainTemplate.dotm.

MyMainTemplate.dotm uses several BuildingBlocks that are stored in MyServiceXx.dotx templates (different templates for different languages: Xx = language).

MyMainTemplate.dotm is located in %APPDATA% + "\Microsoft\Templates"

MyServiceXx.dotx is located in %APPDATA% + \Microsoft\Document Building Blocks*language**version* and is moved in an out this folder on language changes.

In Document_New and Document_Open of MyMainTemplate.dotm I call LoadBuildingBlocks to have all the building blocks ready for use. But I noticed that both New and Open are quite slow to execute both around 1600/1700 milliseconds, and of this time, LoadBuildingBlocks takes around 1200 milliseconds.

When a new document based on MyMainTemplate.dotm is created in the VBE - Project Window I can see:

  • Two instances of Building Blocks.dotx
  • Two instances of Built-In Building Blocks.dotx
  • One instance of MyServiceXx.dotx
  • One instance of MyMainTemplate.dotm

Why to instances of the Microsoft Building Blocks files? In the folder %APPDATA% + \Microsoft\Document Building Blocks*language**version* I can see that the size of Built-In Building Blocks.dotx is 2933 KB*,* MyServiceXx.dotx is 73 KB, instead Building Blocks.dotx is 0 KB.

I'm looking for a workaround to speed the process.

  • Is there a way to load only the building blocks of my MyServiceXx.dotx and leaving the others to the normal management that the Microsoft Application usually does?
  • Is there an event (or other way) to allow the Building Blocks loading to take effect just after the document is fully open and probably the user is still pondering what to do?
  • Should I instead use a register key like a boolean BlocksLoaded set to False when the document is created or open. Then find all my routine using the building blocks and ask them to check the register key is false to run LoadBuildingBlocks and set the register key to True. I'm afraid I'm ending in a mess when several of my documents are simultanously open!

Thanks a lot, Lauro

Microsoft 365 and Office | Development | Other
Microsoft 365 and Office | Install, redeem, activate | For business | Windows
Microsoft 365 and Office | Word | For business | Windows

Locked Question. You can vote on whether it's helpful, but you can't add comments or replies or follow the question.

0 comments No comments
{count} votes
Answer accepted by question author
  1. Charles Kenyon 158.6K Reputation points Volunteer Moderator
    2023-04-11T00:22:19.6833333+00:00

    You could put only your service template in the Startup Folder There is no way you want LoadBuildingBlocks in your AutoOpen or Document_Open procedures, nor would I put it in the AutoNew nor Document_New procedures. LoadBuildingBlocks is all or nothing. If you put the LoadBuildingBlocks command in your AutoExec for the service template that should take care of it. They will load when you start Word.

    That would change your service template to a .dotm template. I do not know that LoadBuildingBlocks in your AutoExec will give access to them in your document template because I have not tried this. I expect that it would and it is worth trying. BTW, AutoExec does not function in document templates, only globals.

    0 comments No comments

4 additional answers

Sort by: Most helpful
  1. Charles Kenyon 158.6K Reputation points Volunteer Moderator
    2023-04-01T20:34:04.3066667+00:00

    Although I have written much about Building Blocks I'm not sure I know enough to address all of your questions. I think the following may help, though.

    First, you do not need to load building blocks every time you open or create a document. This needs to be done once in a Word session. You may want to put it in the AutoExec of your main template add-in.

    Second, I tend to place my custom BBs in Global Templates rather than in the building blocks folder because then I can use AutoComplete for them.

  2. Lauro Colasanti 121 Reputation points
    2023-04-03T17:42:48.41+00:00

    Thanks Charles for your answear.

    I think that for my project a document template is better suited then a global template: in the document template MyMainTemplate.dotm I have several macros for a lot of manipulation of the Content Controls and Building Blocks that the user will insert. On other documents, not well formed for my document template, Those macros are senseless and will obviously conduct to errors.

    The Building Blocks, Style (actually style names), Content Controls, AutoText that the user can insert are languages dependent and are stored by me (but also by the user) in a service template. What I have called MyServiceXx.dotx which I said is only 73 KB. When in Document New or Open I call LoadBuildingBlocks I think that all the Building Blocks (at least those in Built-In Building Blocks.dotx and MyServiceXx.dotx, since my Building Blocks.dotx is empty) are loaded in the memory and ready for use.

    If I comment LoadBuildingBlocks in Document_New of MyMainTemplate.dotm, I get:

    • an error if I try to insert first one of my Building Blocks
    • no error if I insert one of the "normal" BB, for instance, from Insert|Text|Quick Parts|Document Properties|Author and the one of mine BB.

    From your post I gather that I can "economize" time in the loading process only if I use global templates (each session, instead of every documents).

    What about loading only my few ones, instead of the others that are managed by word itself?

    What do you think of putting before every BB insertion a Resume Next instruction to check if they where already loaded otherwise load them?

    Thank again, Lauro

    0 comments No comments
  3. Lauro Colasanti 121 Reputation points
    2023-04-03T17:55:51.0833333+00:00

    Hi Charles, could I put only my service template in the folder for Add-in?

    0 comments No comments
  4. Rosa Doric 0 Reputation points
    2025-12-05T06:36:01.5966667+00:00

    I am trying to find Building Blocks.dotx (English-AUS), does one exist?

    Minor error below:
    When a new document based on MyMainTemplate.dotm is created in the VBE - Project Window I can see:

    • Two instances of Building Blocks.dotx
    • Two instances of Built-In Building Blocks.dotx
    • One instance of MyServiceXx.dotx
    • One instance of MyMainTemplate.dotm

    Why to two instances of the Microsoft Building Blocks files?