How to Insert a Word Building Block from a User Template using a VBA Macro
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.

- 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.
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.
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.
Press ALT + F11 in Word to open the Visual Basic for Applications (VBA) editor, and insert a new Module.
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".
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.

Insert the Building Block Manually via the Insert Ribbon
If you prefer not to use VBA, you can manually insert building blocks saved in your templates directly from Word's interface.
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. Open WPS Writer: Launch WPS Writer and open your working document or letterhead template.
- 2. Access the Insert Tab: Click on the 'Insert' tab on the main ribbon, then look for the 'AutoText' or 'Quick Parts' option.
- 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.

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.




