Hi gang,
I have users taking turns working on a document based on the same template. These users are working on individual computers. They each have a copy of the template installed in the template folder. The template folder path is different for each individual.
I have managed to write code that points the document to the default user template folder and attaches the right template to this document. I am half way there.
I need to create an AutoOpen in every document that will be created based on this template so that every time a user opens the document it will attach the template from that user’s default template folder. I know I will have to put this code in the AutoNew in the template but that is where my “expertise” ends.
Please help.
![]() |
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 |
-
Creating code in a .doc (Word 2000-97 PC-MAC)
Home » Forums » AskWoody support » Productivity software by function » Visual Basic for Applications » Creating code in a .doc (Word 2000-97 PC-MAC)
- This topic has 14 replies, 5 voices, and was last updated 20 years, 5 months ago.
AuthorTopicWSJCSolutions
AskWoody LoungerDecember 7, 2004 at 2:24 am #413227Viewing 1 reply threadAuthorReplies-
Andrew Lockton
AskWoody_MVPDecember 7, 2004 at 3:10 am #909909Are you sure you really need this? Is there other things your macro needs to do beyond just finding a template to attach?
When Word opens a file it has a cascading process for finding the template that is attached to the file. The order appears to be something like this…
1. Use the template in the location specified by the full path for the Attached Template
2. If the template is not there then look in User Templates location for a template with the same name
3. If the template is not there then look in the Workgroup Templates location for a template with the same name
4. If the template is not there then look in the same folder that the Word file is in.5. Give up looking for the template – the Word file will open but you don’t have access to the attached template.
My version of the order is likely to be wrong but the important thing is that Word will happily find the template if it is located in one of four places.
-
WSJCSolutions
AskWoody LoungerDecember 7, 2004 at 1:20 pm #910043Hi Andrew,
Tks for the tip. The workgroup template seems like the logical approach. However, there are dozens of templates and they are separated in different sub folders in the user and/or workgroup templates location. If I put all the templates in a de fault folder it will make it more difficult for the user to find the right template when creating a new doc. By adding code to every new file created with a specific template I can specify the sub-folder in which this template is located.
Would there be a better way of doing this?
Tks -
Andrew Lockton
AskWoody_MVPDecember 7, 2004 at 10:35 pm #910332JC
I would be surprised if you need so many templates that folders are really necessary. You can minimise the number of templates you have by following a philosophy of grouping related content inside a common template.
I prefer to create templates so that some of them contain multiple content options. One template can have different contents added automatically at the start depending on what the user decides they want in the file. This way I can create a consistent look across a series of files and only have to maintain styles/logos/code in one template. The different content options are stored as autotext entries in the template and an autonew macro displays the list which is built dynamically based on the autotext entries in the template at the time.
An example is the difference between having 20 different templates for online forms to having one forms template which allows the user to choose which one of the 20 forms the file should contain.
This approach makes it easy to manage updates to the template and automatically caters for new or changed forms at any time. In some templates the autotext entries might contain 100s of pages of content and the parts that are common to all files (eg cover, disclaimer, toc) are only stored once.
If you are wedded to the separate templates model, what about using a macro in the template that looks to a custom property in the file that contains the path to where the template is held. The macro could then run every time the file is opened and work out which path to set the attached template to by using that path contained in the file. This would let you avoid putting code specifically in the document but still enable a macro to run that is specific to that file.
-
Andrew Lockton
AskWoody_MVPDecember 7, 2004 at 10:35 pm #910333JC
I would be surprised if you need so many templates that folders are really necessary. You can minimise the number of templates you have by following a philosophy of grouping related content inside a common template.
I prefer to create templates so that some of them contain multiple content options. One template can have different contents added automatically at the start depending on what the user decides they want in the file. This way I can create a consistent look across a series of files and only have to maintain styles/logos/code in one template. The different content options are stored as autotext entries in the template and an autonew macro displays the list which is built dynamically based on the autotext entries in the template at the time.
An example is the difference between having 20 different templates for online forms to having one forms template which allows the user to choose which one of the 20 forms the file should contain.
This approach makes it easy to manage updates to the template and automatically caters for new or changed forms at any time. In some templates the autotext entries might contain 100s of pages of content and the parts that are common to all files (eg cover, disclaimer, toc) are only stored once.
If you are wedded to the separate templates model, what about using a macro in the template that looks to a custom property in the file that contains the path to where the template is held. The macro could then run every time the file is opened and work out which path to set the attached template to by using that path contained in the file. This would let you avoid putting code specifically in the document but still enable a macro to run that is specific to that file.
-
WSJanB
AskWoody LoungerDecember 8, 2004 at 11:21 am #910472I fully agree with Andrew concerning the use of multi-purpose templates.
When I took over from my predecessor, there were 300+ templates, scattered all over the place (company server, department server, individual PC’s). Now there are about 70 multi-purpose templates left, all sitting in the WorkgroupTemplates folder.
About 45 are general templates in the main folder, visible to all users. The others are sitting in 4 subfolders named Dep 1, …, Dep 4. Those subfolders are only accessible by authorised users (Novell network folders authorisation model) and so they see a tab with the name of the appropriate department(s), listing the dedicated templates for that department.
Our users are very pleased with this, as it’s very much easier for them to find the template they need and they get “guidance” in the templates themselves as to which choices to make. -
WSJanB
AskWoody LoungerDecember 8, 2004 at 11:21 am #910473I fully agree with Andrew concerning the use of multi-purpose templates.
When I took over from my predecessor, there were 300+ templates, scattered all over the place (company server, department server, individual PC’s). Now there are about 70 multi-purpose templates left, all sitting in the WorkgroupTemplates folder.
About 45 are general templates in the main folder, visible to all users. The others are sitting in 4 subfolders named Dep 1, …, Dep 4. Those subfolders are only accessible by authorised users (Novell network folders authorisation model) and so they see a tab with the name of the appropriate department(s), listing the dedicated templates for that department.
Our users are very pleased with this, as it’s very much easier for them to find the template they need and they get “guidance” in the templates themselves as to which choices to make. -
WSGary Frieder
AskWoody LoungerJanuary 1, 2005 at 8:40 am #917383Ms. JC,
Just stumbled on this thread, and don’t know if it’s now outdated and you have found a solution, anyway:
Notwithstanding Andrew and Jan’s valid suggestions about reducing the number of templates you (and your users) have to deal with, it seems like there is still a missing link in the situation you are describing – are you saying you need this code to run, every time a document based on a specific template is opened, to locate the appropriate template on that individual user’s profile, and reattach that template?
If so, then housing the needed code in the template’s Document_Open or AutoOpen procedure won’t do the trick, because that code won’t even run when the document is opened, if the document is not currently attached to the relevant template that contains the code.
Neither is putting the code into a procedure in the document itself a good approach – as a general rule, you don’t want to be propagating code-bearing documents out into the world – code should stay in the template.
If you do have to run some code to manage the locations of lots of different templates and attach documents to correct templates on Open, then the best place to house that code would be in a global add-in template. You would need to set up an application-level DocumentOpen event procedure. Code in that procedure could determine the name of the template for every document that opens, and then further code could attach the correct template, for those documents that need it.
If the above is relevant to what you’re trying to do, and you need more detail, write back and I’ll track down some working code.Gary
-
WSfrankpasztor
AskWoody Lounger -
WSGary Frieder
AskWoody LoungerJanuary 4, 2005 at 1:43 am #918053Assuming for the moment that we’re going to house the code in the document itself – in its ThisDocument module – the next question would be: how do you get the code in there to begin with?
If you put code in a template’s ThisDocument module, that code isn’t going to propagate out to the ThisDocument module of the documents that get created based on the template. So, you’d either have to:
(1) abandon creating documents based on templates. Instead, put all of the needed code into a ‘document which serves as a template’, and always create new documents by opening this ur-document and doing a FileSaveAs. That does create some circular logic though, because if the documents are not going to be based on a template, then you don’t need to be running code to find the document’s template, anyway! The main problem with this approach is that you’re working against the way Word is designed, and giving up the advantages of housing things like code, custom toolbars and autotexts in the template, rather than the document. (On the other hand, that’s how it works in Excel….)
(2) stay with the template/document structure, and have code in the template’s Document_New procedure, which writes the needed code into the Document_Open procedure of each new document, at the time that it’s created – maybe that’s what the original poster is looking to do. Haven’t ever done that myself, but I’m sure it’s possible to do – I’d be nervous that this approach might set off alerts from antivirus software, but if you can get past that, it might be OK.
I still think it’s more straightforward to have any needed code like this, live in a global template, rather than either of (1) or (2) above.
Gary
-
WSGary Frieder
AskWoody LoungerJanuary 4, 2005 at 1:43 am #918054Assuming for the moment that we’re going to house the code in the document itself – in its ThisDocument module – the next question would be: how do you get the code in there to begin with?
If you put code in a template’s ThisDocument module, that code isn’t going to propagate out to the ThisDocument module of the documents that get created based on the template. So, you’d either have to:
(1) abandon creating documents based on templates. Instead, put all of the needed code into a ‘document which serves as a template’, and always create new documents by opening this ur-document and doing a FileSaveAs. That does create some circular logic though, because if the documents are not going to be based on a template, then you don’t need to be running code to find the document’s template, anyway! The main problem with this approach is that you’re working against the way Word is designed, and giving up the advantages of housing things like code, custom toolbars and autotexts in the template, rather than the document. (On the other hand, that’s how it works in Excel….)
(2) stay with the template/document structure, and have code in the template’s Document_New procedure, which writes the needed code into the Document_Open procedure of each new document, at the time that it’s created – maybe that’s what the original poster is looking to do. Haven’t ever done that myself, but I’m sure it’s possible to do – I’d be nervous that this approach might set off alerts from antivirus software, but if you can get past that, it might be OK.
I still think it’s more straightforward to have any needed code like this, live in a global template, rather than either of (1) or (2) above.
Gary
-
-
-
WSfrankpasztor
AskWoody Lounger
-
-
-
WSGary Frieder
AskWoody LoungerJanuary 1, 2005 at 8:40 am #917384Ms. JC,
Just stumbled on this thread, and don’t know if it’s now outdated and you have found a solution, anyway:
Notwithstanding Andrew and Jan’s valid suggestions about reducing the number of templates you (and your users) have to deal with, it seems like there is still a missing link in the situation you are describing – are you saying you need this code to run, every time a document based on a specific template is opened, to locate the appropriate template on that individual user’s profile, and reattach that template?
If so, then housing the needed code in the template’s Document_Open or AutoOpen procedure won’t do the trick, because that code won’t even run when the document is opened, if the document is not currently attached to the relevant template that contains the code.
Neither is putting the code into a procedure in the document itself a good approach – as a general rule, you don’t want to be propagating code-bearing documents out into the world – code should stay in the template.
If you do have to run some code to manage the locations of lots of different templates and attach documents to correct templates on Open, then the best place to house that code would be in a global add-in template. You would need to set up an application-level DocumentOpen event procedure. Code in that procedure could determine the name of the template for every document that opens, and then further code could attach the correct template, for those documents that need it.
If the above is relevant to what you’re trying to do, and you need more detail, write back and I’ll track down some working code.Gary
WSJCSolutions
AskWoody LoungerDecember 7, 2004 at 1:20 pm #910044Hi Andrew,
Tks for the tip. The workgroup template seems like the logical approach. However, there are dozens of templates and they are separated in different sub folders in the user and/or workgroup templates location. If I put all the templates in a de fault folder it will make it more difficult for the user to find the right template when creating a new doc. By adding code to every new file created with a specific template I can specify the sub-folder in which this template is located.
Would there be a better way of doing this?
TksAndrew Lockton
AskWoody_MVPDecember 7, 2004 at 3:10 am #909910Are you sure you really need this? Is there other things your macro needs to do beyond just finding a template to attach?
When Word opens a file it has a cascading process for finding the template that is attached to the file. The order appears to be something like this…
1. Use the template in the location specified by the full path for the Attached Template
2. If the template is not there then look in User Templates location for a template with the same name
3. If the template is not there then look in the Workgroup Templates location for a template with the same name
4. If the template is not there then look in the same folder that the Word file is in.5. Give up looking for the template – the Word file will open but you don’t have access to the attached template.
My version of the order is likely to be wrong but the important thing is that Word will happily find the template if it is located in one of four places.
Viewing 1 reply thread -

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
-
Mozilla quietly tests Perplexity AI as a New Firefox Search Option
by
Alex5723
57 minutes ago -
LibreOffice 25.8. No Windows 7, 8/8.1, x86
by
Alex5723
4 hours ago -
Perplexity Pro free for 12 mos for Samsung Galaxy phones
by
Patricia Grace
19 hours, 56 minutes ago -
June KB5060842 update broke DHCP server service
by
Alex5723
18 hours, 28 minutes ago -
AMD Ryzen™ Chipset Driver Release Notes 7.06.02.123
by
Alex5723
22 hours, 31 minutes ago -
Excessive security alerts
by
WSSebastian42
54 minutes ago -
* CrystalDiskMark may shorten SSD/USB Memory life
by
Alex5723
1 day, 7 hours ago -
Ben’s excellent adventure with Linux
by
Ben Myers
1 hour, 18 minutes ago -
Seconds are back in Windows 10!
by
Susan Bradley
19 hours, 7 minutes ago -
WebBrowserPassView — Take inventory of your stored passwords
by
Deanna McElveen
1 hour, 41 minutes ago -
OS news from WWDC 2025
by
Will Fastie
5 hours, 16 minutes ago -
Need help with graphics…
by
WSBatBytes
3 hours, 17 minutes ago -
AMD : Out of Bounds (OOB) read vulnerability in TPM 2.0 CVE-2025-2884
by
Alex5723
1 day, 23 hours ago -
Totally remove or disable BitLocker
by
CWBillow
22 hours, 34 minutes ago -
Windows 10 gets 6 years of ESU?
by
n0ads
1 day, 1 hour ago -
Apple, Google stores still offer China-based VPNs, report says
by
Nibbled To Death By Ducks
2 days, 10 hours ago -
Search Forums only bring up my posts?
by
Deo
4 hours, 39 minutes ago -
Windows Spotlight broken on Enterprise and Pro for Workstations?
by
steeviebops
2 days, 21 hours ago -
Denmark wants to dump Microsoft for Linux + LibreOffice
by
Alex5723
2 days, 14 hours ago -
How to get Microsoft Defender to honor Group Policy Setting
by
Ralph
2 days, 22 hours ago -
Apple : Paragon’s iOS Mercenary Spyware Finds Journalists Target
by
Alex5723
3 days, 8 hours ago -
Music : The Rose Room – It’s Been A Long, Long Time album
by
Alex5723
3 days, 9 hours ago -
Disengage Bitlocker
by
CWBillow
2 days, 23 hours ago -
Mac Mini M2 Service Program for No Power Issue
by
Alex5723
3 days, 11 hours ago -
New Win 11 Pro Geekom Setup questions
by
Deo
4 hours, 44 minutes ago -
Windows 11 Insider Preview build 26200.5651 released to DEV
by
joep517
3 days, 19 hours ago -
Windows 11 Insider Preview build 26120.4441 (24H2) released to BETA
by
joep517
3 days, 19 hours ago -
iOS 26,, MacOS 26 : Create your own AI chatbot
by
Alex5723
3 days, 22 hours ago -
New PC transfer program recommendations?
by
DaveBoston
2 days, 3 hours ago -
Windows 11 Insider Preview Build 22631.5545 (23H2) released to Release Preview
by
joep517
4 days, 3 hours ago
Recent blog posts
- Ben’s excellent adventure with Linux
- Seconds are back in Windows 10!
- WebBrowserPassView — Take inventory of your stored passwords
- OS news from WWDC 2025
- Best tools for upgrading a Windows 10 to an 11
- Master patch listing for June 10, 2025
- 24H2 may not be offered June updates
- June 2025 updates are out
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.