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, 7 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
-
Notice on termination of services of LG Mobile Phone Software Updates
by
Alex5723
8 hours, 40 minutes ago -
Update your Apple Devices Wormable Zero-Click Remote Code Execution in AirPlay..
by
Alex5723
4 hours, 41 minutes ago -
Amazon denies it had plans to be clear about consumer tariff costs
by
Alex5723
11 hours, 5 minutes ago -
Return of the brain dead FF sidebar
by
EricB
1 hour, 42 minutes ago -
windows settings managed by your organization
by
WSDavidO61
5 hours, 47 minutes ago -
Securing Laptop for Trustee Administrattor
by
PeachesP
6 hours ago -
The local account tax
by
Susan Bradley
1 hour, 50 minutes ago -
Recall is back with KB5055627(OS Build 26100.3915) Preview
by
Alex5723
17 hours, 42 minutes ago -
Digital TV Antenna Recommendation
by
Win7and10
10 hours, 14 minutes ago -
Server 2019 Domain Controllers broken by updates
by
MP Support
1 day, 5 hours ago -
Google won’t remove 3rd party cookies in Chrome as promised
by
Alex5723
1 day, 7 hours ago -
Microsoft Manager Says macOS Is Better Than Windows 11
by
Alex5723
1 day, 10 hours ago -
Outlook (NEW) Getting really Pushy
by
RetiredGeek
12 hours, 51 minutes ago -
Steps to take before updating to 24H2
by
Susan Bradley
3 hours, 40 minutes ago -
Which Web browser is the most secure for 2025?
by
B. Livingston
17 hours, 17 minutes ago -
Replacing Skype
by
Peter Deegan
5 hours, 50 minutes ago -
FileOptimizer — Over 90 tools working together to squish your files
by
Deanna McElveen
1 day, 4 hours ago -
Excel Macro — ask for filename to be saved
by
nhsj
1 hour, 47 minutes ago -
Trying to backup Win 10 computer to iCloud
by
SheltieMom
5 hours, 37 minutes ago -
Windows 11 Insider Preview build 26200.5570 released to DEV
by
joep517
3 days, 10 hours ago -
Windows 11 Insider Preview build 26120.3941 (24H2) released to BETA
by
joep517
3 days, 12 hours ago -
Windows 11 Insider Preview Build 22635.5305 (23H2) released to BETA
by
joep517
3 days, 12 hours ago -
No April cumulative update for Win 11 23H2?
by
Peobody
2 days ago -
AugLoop.All (TEST Augmentation Loop MSIT)
by
LarryK
3 days, 12 hours ago -
Boot Sequence for Dell Optiplex 7070 Tower
by
Serge Carniol
4 days, 3 hours ago -
OTT Upgrade Windows 11 to 24H2 on Unsupported Hardware
by
bbearren
4 days, 7 hours ago -
Inetpub can be tricked
by
Susan Bradley
2 days, 14 hours ago -
How merge Outlook 2016 .pst file w/into newly created Outlook 2024 install .pst?
by
Tex265
3 days, 1 hour ago -
FBI 2024 Internet Crime Report
by
Alex5723
4 days, 11 hours ago -
Perplexity CEO says its browser will track everything users do online
by
Alex5723
1 day, 20 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.