Template Issues

How to Insert a Word Building Block from a User Template using a VBA Macro

Adam DavisAdam Davis Oct 29, 2026 870 views

Question details

The user needs to write a VBA macro that inserts a letterhead building block from a template stored in the user's Startup folder without hardcoding a specific computer path.

How to Insert a Building Block from a User Template using a Word VBA Macro
Product
Microsoft Word
Device & OS
not provided
Scenario
Deploying a VBA macro across multiple users to insert template-specific building blocks dynamically.
Observed behavior
The macro needs a dynamic path reference because hardcoded file paths fail when the template is accessed on different computers with different usernames.
Before you start

Ensure that the Developer tab is enabled in your Word ribbon and that your target template containing the building blocks is properly saved in the Word Startup directory.

Solution 1Recommended

Build the Template Path Dynamically with Windows APPDATA Variable

Use the Windows environment variable for the roaming application-data folder to retrieve the user's specific path dynamically without hardcoding usernames.

Hardcoding paths like 'C:\Users\JohnDoe\AppData\...' causes macros to fail when shared. By utilizing the VBA Environ function, you can dynamically retrieve the path to the current user's AppData\Roaming directory. This ensures the macro successfully locates the Startup folder on any computer.

1
Open the VBA Editor

Press ALT + F11 in Word to open the Visual Basic for Applications (VBA) editor, and insert a new Module.

2
Construct the Dynamic Path

In your macro code, use 'Environ("APPDATA")' to retrieve the roaming folder. Construct the full path by appending the specific folder structure, such as: strPath = Environ("APPDATA") & "\Microsoft\Word\STARTUP\YourTemplate.dotm".

3
Reference the Template and Insert the Building Block

Use the 'Templates' collection to load the dynamically referenced file. Then, use the 'BuildingBlockEntries' method to specify the category and name of your letterhead, and insert it into the active document at the Selection point.

Build the Template Path Dynamically with Windows APPDATA Variable
Macro Distribution: Using this environment variable ensures that your macro can be safely distributed to other users in your organization without requiring manual code adjustments.

Efficiently Manage AutoText and Templates with WPS Office

WPS Writer provides intuitive built-in tools for managing reusable document content like letterheads and text blocks. You can easily save and insert standardized content without needing complex VBA scripts.

  1. 1. Open WPS Writer: Launch WPS Writer and open your working document or letterhead template.
  2. 2. Access the Insert Tab: Click on the 'Insert' tab on the main ribbon, then look for the 'AutoText' or 'Quick Parts' option.
  3. 3. Manage and Insert Content: Select your pre-saved building block to insert it instantly, or highlight text to save it as a new reusable block for future documents.
Fully compatible with Microsoft Word (.docx, .dotm) formats and templates.Built-in AutoText and Quick Parts features for fast insertion of standard content.Lightweight software architecture that loads documents and templates instantly.Free to use with a familiar interface that requires no learning curve.
QA img-9

Frequently Asked Questions

What does Environ("APPDATA") do in a VBA macro?

It is a built-in VBA function that retrieves the Windows environment variable for the current user's Application Data folder (typically C:\Users\[Username]\AppData\Roaming). This allows the macro to dynamically locate user-specific system folders regardless of who is logged into the computer.

Can I record a macro to insert a building block instead of writing it from scratch?

Yes, you can use Word's Macro Recorder while manually inserting the building block. However, the recorded code often hardcodes the specific file path and gallery index. You will usually need to edit the recorded VBA code manually to replace the static path with the Environ("APPDATA") method.

Where should I store Word templates so macros can easily access them globally?

For global access across all documents, templates containing building blocks and macros should be saved in the Word Startup folder, which is generally located at %appdata%\Microsoft\Word\STARTUP.