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, but widespread attacks make patching prudent. Go ahead and patch, but watch out for potential problems. |
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
-
MS-DEFCON 3: Businesses must tread carefully
by
Susan Bradley
28 minutes ago -
McLaren Health Care says data breach impacts 743,000 patients
by
Nibbled To Death By Ducks
8 hours, 35 minutes ago -
WhatsApp banned on House staffers’ devices
by
Alex5723
3 hours, 37 minutes ago -
Is your device eligible?
by
Susan Bradley
11 hours, 35 minutes ago -
Windows 11 Insider Preview build 26200.5661 released to DEV
by
joep517
17 hours, 46 minutes ago -
Windows 11 Insider Preview build 26120.4452 (24H2) released to BETA
by
joep517
17 hours, 47 minutes ago -
Hello Windows…My Problem is Windows Hello…
by
rdleib
19 hours, 3 minutes ago -
New Canon Printer Wants Data Sent
by
Win7and10
19 hours, 21 minutes ago -
I set up passkeys for my Microsoft account
by
Lance Whitney
8 hours, 51 minutes ago -
AI is for everyone
by
Peter Deegan
18 hours, 54 minutes ago -
Terabyte update 2025
by
Will Fastie
12 hours, 57 minutes ago -
Migrating from Windows 10 to Windows 11
by
Susan Bradley
8 hours, 30 minutes ago -
Lost sound after the upgrade to 24H2?
by
Susan Bradley
1 day, 18 hours ago -
How to move 10GB of data in C:\ProgramData\Package Cache ?
by
Alex5723
1 hour, 1 minute ago -
Plugged in 24-7
by
CWBillow
1 day, 4 hours ago -
Netflix, Apple, BofA websites hijacked with fake help-desk numbers
by
Nibbled To Death By Ducks
2 days, 7 hours ago -
Have Copilot there but not taking over the screen in Word
by
CWBillow
2 days, 4 hours ago -
Windows 11 blocks Chrome 137.0.7151.68, 137.0.7151.69
by
Alex5723
3 days, 22 hours ago -
Are Macs immune?
by
Susan Bradley
13 hours, 56 minutes ago -
HP Envy and the Function keys
by
CWBillow
3 days, 6 hours ago -
Microsoft : Removal of unwanted drivers from Windows Update
by
Alex5723
23 hours, 25 minutes ago -
MacOS 26 beta 1 dropped support for Firewire 400/800
by
Alex5723
4 days, 9 hours ago -
Unable to update to version 22h2
by
04om
1 day, 18 hours ago -
Windows 11 Insider Preview Build 26100.4482 (24H2) released to Release Preview
by
joep517
4 days, 17 hours ago -
Windows 11 Insider Preview build 27881 released to Canary
by
joep517
4 days, 17 hours ago -
Very Quarrelsome Taskbar!
by
CWBillow
4 days, 3 hours ago -
Move OneNote Notebook OFF OneDrive and make it local
by
CWBillow
5 days, 6 hours ago -
Microsoft 365 to block file access via legacy auth protocols by default
by
Alex5723
4 days, 19 hours ago -
Is your battery draining?
by
Susan Bradley
1 day, 1 hour ago -
The 16-billion-record data breach that no one’s ever heard of
by
Alex5723
1 day, 18 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.