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.
![]() |
There are isolated problems with current patches, but they are well-known and documented on this site. |
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, 8 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
-
Rufus is available from the MSFT Store
by
PL1
2 hours, 2 minutes ago -
Microsoft : Ending USB-C® Port Confusion
by
Alex5723
4 hours, 11 minutes ago -
KB5061768 update for Intel vPro processor
by
drmark
24 minutes ago -
Outlook 365 classic has exhausted all shared resources
by
drmark
2 hours, 22 minutes ago -
My Simple Word 2010 Macro Is Not Working
by
mbennett555
19 hours, 22 minutes ago -
Office gets current release
by
Susan Bradley
2 hours, 34 minutes ago -
FBI: Still Using One of These Old Routers? It’s Vulnerable to Hackers
by
Alex5723
1 day, 16 hours ago -
Windows AI Local Only no NPU required!
by
RetiredGeek
1 day, 1 hour ago -
Stop the OneDrive defaults
by
CWBillow
1 day, 17 hours ago -
Windows 11 Insider Preview build 27868 released to Canary
by
joep517
2 days, 3 hours ago -
X Suspends Encrypted DMs
by
Alex5723
2 days, 5 hours ago -
WSJ : My Robot and Me AI generated movie
by
Alex5723
2 days, 5 hours ago -
Botnet hacks 9,000+ ASUS routers to add persistent SSH backdoor
by
Alex5723
2 days, 6 hours ago -
OpenAI model sabotages shutdown code
by
Cybertooth
2 days, 7 hours ago -
Backup and access old e-mails after company e-mail address is terminated
by
M W Leijendekker
1 day, 19 hours ago -
Enabling Secureboot
by
ITguy
2 days, 2 hours ago -
Windows hosting exposes additional bugs
by
Susan Bradley
2 days, 15 hours ago -
No more rounded corners??
by
CWBillow
2 days, 10 hours ago -
Android 15 and IPV6
by
Win7and10
2 days ago -
KB5058405 might fail to install with recovery error 0xc0000098 in ACPI.sys
by
Susan Bradley
3 days, 3 hours ago -
T-Mobile’s T-Life App has a “Screen Recording Tool” Turned on
by
Alex5723
3 days, 6 hours ago -
Windows 11 Insider Preview Build 26100.4202 (24H2) released to Release Preview
by
joep517
3 days ago -
Windows Update orchestration platform to update all software
by
Alex5723
3 days, 13 hours ago -
May preview updates
by
Susan Bradley
3 days ago -
Microsoft releases KB5061977 Windows 11 24H2, Server 2025 emergency out of band
by
Alex5723
2 days, 16 hours ago -
Just got this pop-up page while browsing
by
Alex5723
3 days, 5 hours ago -
KB5058379 / KB 5061768 Failures
by
crown
3 days, 2 hours ago -
Windows 10 23H2 Good to Update to ?
by
jkitc
2 days, 4 hours ago -
At last – installation of 24H2
by
Botswana12
4 days, 4 hours ago -
MS-DEFCON 4: As good as it gets
by
Susan Bradley
2 hours, 49 minutes 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.