Problem:I have word documents based on templates from 2 different server locations. I have just combined the 2 different locations into one. I need to check all documents and re-write the correct path to the now common workgroup template location.
What is the correct VBA property to get at the path information? When I use ActiveDocument.BuiltInDocumentProperties(wdTemplateProperty), I see the template name only, not the path.
When I use ActiveDocument.AttachedTemplate.FullName, I only see the Normal.dot template.
As an alternative I have thought about scanning the entire document looking for the known incorrect path string but this seems quite inefficient.
![]() |
Patch reliability is unclear. Unless you have an immediate, pressing need to install a specific patch, don't do it. |
SIGN IN | Not a member? | REGISTER | PLUS MEMBERSHIP |
-
VBA property to find path of attached template
Home » Forums » AskWoody support » Productivity software by function » Visual Basic for Applications » VBA property to find path of attached template
- This topic has 7 replies, 4 voices, and was last updated 12 years, 9 months ago.
AuthorTopicMacdonellTo
AskWoody LoungerAugust 31, 2012 at 4:59 pm #485147Viewing 3 reply threadsAuthorReplies-
richardbarrett
AskWoody Lounger -
kdock
AskWoody PlusSeptember 1, 2012 at 5:24 pm #1347648macdonell,
I’ve successfully switched templates with code like this:
Code:Sub ChangeAttachedTemplate() Dim oDoc As Document ‘make sure you’re getting info on the right document Set oDoc = ActiveDocument If oDoc.Type = wdTypeTemplate Then Exit Sub Dim oTemplate As Template Dim strTemplatePath Set oTemplate = oDoc.AttachedTemplate If InStr(UCase(oTemplate.FullName), “OLDPATH”) > 0 Then oDoc.AttachedTemplate = “FULLNEWPATH” & oTemplate.Name End If End Sub
The code I used had a few more Ifs, but it works for me.
Does this help?
Kim -
WSBigMac56
AskWoody LoungerSeptember 5, 2012 at 11:43 pm #1348064Do your templates rely on some extra pathing? Word should look at it’s default path and go from there. Anything in the “general” directory should not be a problem. If you keep the sub directories the same name when transferring the templates, most should be fine.
But I do recall some instances where we used a macro to dig out the path to the Workgroup directory, and then appended the name of the subdirectory we needed. Sorry, don’t work there anymore. -
MacdonellTo
AskWoody LoungerSeptember 9, 2012 at 5:35 pm #1348661Thank you for the suggestions. A bit more back ground information about my issue.
Most of the files in question have been created with Word2000 or 2002.
At the same time of combining the 2 separate servers (1-win2000 & 1-Win7) into one, I have been upgrading the user PCs with Win7 and Office 2010. This upgrade finished before the all the files were completely moved and combined into one of those existing servers (Win7).
The users were commenting some Word files took a longtime to open. They were using Word2010 now.When I looked, I noticed on the status line, a message indicating the Word was looking for the old server that had been turned off. Eventually a time-out occurred and the file appeared on the users’ screen. I turned the old server back on and the problem went away.
Starting to dig around, I opened some of the files with Notepad and saw the same path information and template name that was showing on the status line when a file was being opened but the old server was turned off.That is when I assumed that if I found the VBA code, I could merely rewrite the WorkGroup Path information of the particular template, that had been used to create the Word document. I thought everything would be fine now.
I have not been able to find any reference to this item in VBA. There is code to rewrite the Workgroup Path but that resides in the application Word.
AttachedTemplate.Path or .FullName produced the path and name of the Normal template attached to the file. Finally, I realized that the AttachedTemplate property was not appropriate as the creating template was not attached to the document.
Out of desparation, using the code idea from Kim, I rewrote the Path for the normal.dotm file that was always shown as the attached template.Sub UpdateTemplServPath()
Dim NTemplate As Template
If ActiveDocument.Type = wdTypeTemplate Then Exit Sub ‘Do nothing if this is a template. It has to be a document
Set NTemplate = ActiveDocument.AttachedTemplate ‘Gets name of normal.dotm attached template
‘Path is on local PC but is ignored at this point
ActiveDocument.AttachedTemplate = “\serverDH Templates” & NTemplate
‘Path is now rewritten to be new server along with normal.dotm template name
ActiveDocument.Save ‘document is saved with new path info
End SubWonder of wonders, the next time I attempted to open the document, it opened with no delay!
When I attempted to verify this by using Notepad, I could not find any ASCII readout of the WorkGroup path. I am assuming that this is because the file was rewritten according to the newer Word 2010 format.This seems to have worked. I do not understand why. I hope that there are no side effects to this action.
If someone can shed some light on what is happening inside Word, I would appreciate it.
Thanks again for simulating my thoughts towards a solution. -
MacdonellTo
AskWoody LoungerSeptember 11, 2012 at 1:18 pm #1348779 -
kdock
AskWoody PlusSeptember 11, 2012 at 5:36 pm #1348788macdonell,
A Word document remembers the template from which it was created. When the original template is not available (for example, you move it to your personal laptop), Word temporarily attaches the document to the default Normal template.
If you go to Developer tab > Templates group > Document Template button, you’ll see at the top of the dialog that it still points to the old location. But if you look at the document in the project pane in the VBE, you’ll see that the document has a (temp) reference to Normal.dotm. When the document returns “home” it will again look for its template. If it doesn’t find it, Word will again attach it to Normal.
Word works pretty hard to find the template before it attaches Normal. Consider this:
-
[*]I created a document based on a template in my workgroup location.
[*]I closed the document and moved the template to another folder.
[*]I opened the document and looked in the Document Template dialog and it pointed to the new location.
[*]I closed the document and moved the template to my desktop.
[*]The Document Template dialog now showed that BasicDoc was now on my desktop.Because each location was on my computer, it all happened pretty quickly. Searching a network could easily account for the time it took your users to open documents. I don’t know the parameters of Word’s search. Mapped drives? When I moved the template off my computer and onto a USB flash drive, Word didn’t find it.
Ultimately, I believe there should be no side effects to your solution. However, whatever assets were in the original template (styles, autotext/quick parts, macros) will no longer be available to the document. This may not be an issue at your company.
Was your ultimate goal to attach to the Normal template or to attach to the relocated (original) template? Or just to get the darned things opened?
I wonder if this might help? I dug up this simple code which lets you return the path and name that appears in the Document Template dialog:
Code:Sub WhichTemplate() Dim strTPath As String strTPath = Dialogs(wdDialogToolsTemplates).Template MsgBox strTPath, vbOKOnly, “Your template path is…” End Sub
…whether the template is still there or not. Whereas ActiveDocument.AttachedTemplate will (as you’ve found) return “Normal.dotm”.
Best, Kim
-
-
-
-
WSBigMac56
AskWoody LoungerSeptember 10, 2012 at 3:46 pm #1348735I’ve run into that before. Word “remembers” the document template that the document or template was based on and searches for it, causing long delays. If you click on the “Developer tab”,and then “Document Template” (doc must be unprotected), the path to the original template will be highlighted. Simply pressing the Delete key will erase it, and saving should cause it to point to your current Normal.dotx and eliminate the problem for that document.
You’re better at programming than I, so I’ll leave the rest to you.Doug Mac
Viewing 3 reply threads -

Plus Membership
Donations from Plus members keep this site going. You can identify the people who support AskWoody by the Plus badge on their avatars.
AskWoody Plus members not only get access to all of the contents of this site -- including Susan Bradley's frequently updated Patch Watch listing -- they also receive weekly AskWoody Plus Newsletters (formerly Windows Secrets Newsletter) and AskWoody Plus Alerts, emails when there are important breaking developments.
Get Plus!
Welcome to our unique respite from the madness.
It's easy to post questions about Windows 11, Windows 10, Win8.1, Win7, Surface, Office, or browse through our Forums. Post anonymously or register for greater privileges. Keep it civil, please: Decorous Lounge rules strictly enforced. Questions? Contact Customer Support.
Search Newsletters
Search Forums
View the Forum
Search for Topics
Recent Topics
-
Windows 11 ad from Campaign Manager in Windows 10
by
Jim McKenna
15 hours, 58 minutes ago -
Small desktops
by
Susan Bradley
1 hour, 49 minutes ago -
Totally disable Bitlocker
by
CWBillow
2 hours, 3 minutes ago -
Phishers extract Millions from HMRC accounts..
by
Microfix
1 day ago -
Windows 10 22H2 Update today (5 June) says up-to-date but last was 2025-04
by
Alan_uk
1 day, 2 hours ago -
Thoughts on Malwarebytes Scam Guard for Mobile?
by
opti1
1 day, 5 hours ago -
Mystical Desktop
by
CWBillow
1 day, 5 hours ago -
Meta and Yandex secretly tracked billions of Android users
by
Alex5723
11 hours, 9 minutes ago -
MS-DEFCON 2: Do you need that update?
by
Susan Bradley
10 minutes ago -
CD/DVD drive is no longer recognized
by
WSCape Sand
1 day, 21 hours ago -
Windows 11 24H2 Default Apps stuck on Edge and Adobe Photoshop
by
MikeBravo
1 day, 23 hours ago -
North Face and Cartier customer data stolen in cyber attacks
by
Alex5723
1 day, 21 hours ago -
What is wrong with simple approach?
by
WSSpoke36
1 day, 14 hours ago -
Microsoft-Backed Builder.ai Set for Bankruptcy After Cash Seized
by
Alex5723
2 days, 9 hours ago -
Location, location, location
by
Susan Bradley
23 hours, 50 minutes ago -
Cannot get a task to run a restore point
by
CWBillow
2 days, 10 hours ago -
Frustrating search behavior with Outlook
by
MrJimPhelps
2 days, 1 hour ago -
June 2025 Office non-Security Updates
by
PKCano
2 days, 21 hours ago -
Secure Boot Update Fails after KB5058405 Installed
by
SteveIT
1 day ago -
Firefox Red Panda Fun Stuff
by
Lars220
2 days, 21 hours ago -
How start headers and page numbers on page 3?
by
Davidhs
3 days, 7 hours ago -
Attack on LexisNexis Risk Solutions exposes data on 300k +
by
Nibbled To Death By Ducks
2 days, 10 hours ago -
Windows 11 Insider Preview build 26200.5622 released to DEV
by
joep517
3 days, 16 hours ago -
Windows 11 Insider Preview build 26120.4230 (24H2) released to BETA
by
joep517
3 days, 16 hours ago -
MS Excel 2019 Now Prompts to Back Up With OneDrive
by
lmacri
3 days, 6 hours ago -
Firefox 139
by
Charlie
2 days, 22 hours ago -
Who knows what?
by
Will Fastie
2 days, 1 hour ago -
My top ten underappreciated features in Office
by
Peter Deegan
3 hours, 51 minutes ago -
WAU Manager — It’s your computer, you are in charge!
by
Deanna McElveen
1 day, 10 hours ago -
Misbehaving devices
by
Susan Bradley
2 days, 13 hours ago
Recent blog posts
Key Links
Want to Advertise in the free newsletter? How about a gift subscription in honor of a birthday? Send an email to sb@askwoody.com to ask how.
Mastodon profile for DefConPatch
Mastodon profile for AskWoody
Home • About • FAQ • Posts & Privacy • Forums • My Account
Register • Free Newsletter • Plus Membership • Gift Certificates • MS-DEFCON Alerts
Copyright ©2004-2025 by AskWoody Tech LLC. All Rights Reserved.