Document_New or AutoNew() macro

E

EdC

I'd like to add a macro to templates that are stored on a network, suc
that when users open a document based on these templates, the link wit
the network is broken.

This is to solve the issue that arises when documents based upon
network template are sent to other locations, the result being tha
Word attempts to find the template location defined in Tools/Template
and Add-Ins.

I understand that copying templates to a user's local drive the
updating them using a login script is a better way of doing things, bu
I've got more familiarity with Word macros/VBA than with login script
(but not much).

I'd be grateful if anyone could suggest such a macro or a goo
description of how to write one.

Many thanks
 
P

Peter Hewett

Hi Edc

You don't actually need to do anything. Word goes through a rather
convoluted process to track down the attached template (the template used
to create the original document) when you open an existing document. If
however, Word cannot locate the attached template it attaches the document
to Normal.dot.

The attached template however is not an Add-In. Add-Ins are loaded when
Word starts, but they are not (or should not be if you are) used for
creating documents. Templates are used for creating documents, Add-Ins are
used as shared code libraries.

The template(s) you're using to create a document may contain a VBA Project
Reference to the Add-In, but that should not make any difference to your
document on another computer. The reason for this is simple, since Word
can't find your template on the other system it can't open it and
consequently wont try to reference the non-existant Add-In either.

For your reference when Word opens a document it looks in the following
folders in this order:

1. Workgroup Templates folder (Tools>Options>File Locations)
2. User Templates (Tools>Options>File Locations)
3. ?:\Program Files\Microsoft Office\Office

===========================================================================
NOTE: If you create a document from a template in "User Templates" and you
have a template with the same name in "Workgroup Templates" next time you
open your document Word will attach it to the template in "Workgroup
Templates" and NOT "User Templates" as you would expect.
===========================================================================

If this does not clear thing up please post again.

HTH + Cheers - Peter
 
J

Jean-Guy Marcil

Hi Peter,

And, I believe there is a fourth location and a fifth location:

The fourth location is the folder containing the document itself. And that
one is priority one.
For the fifth, see at the end of my post...

I have just done some tests with Windows and Office XP:

I create a document from a template from the User folder;
Then save it somewhere (D:\);
Close Word;
Then I copy the template to the Workgroup folder;
Open my doc;
It is still attached to the user template;
Close Word;
Delete the template from the User folder;
Open my doc;
It is now attached to the template in the Workgroup Template;
I copy the template back to the User folder;
Delete the one form the Workgroup folder;
Copy the template to D:\ (Where my document is stored);
Open the document;
It is now attached to the template at D:\, not the available one in the User
folder.

I did all kinds of other tests, I even tried with the template at three or
four locations simultaneously.

Unless I have missed something; my conclusions are (Regarding the priority
order for attaching a template when loading a document):

1. Folder containing the active document
2. User Templates (Tools>Options>File Locations)
3. Workgroup Templates folder (Tools>Options>File Locations)
4. ?:\Program Files\Microsoft Office\Office10 (for XP)
and the fifth...
5. ?:\Program Files\Microsoft Office\Office (for XP)

This last one is very strange, Consider the following:
I create a document based on a template in one of the other four locations,
let's say User folder;
Then I close Word:
Move the template from the User folder to the fifth location;
Open the doc;
The Models and Add-ins dialog tells me my document is attached to a template
located in the User Folder, even if it is actually in that fifth location
(and does not exists anymore in the User folder)!

I did a lot of testing with that last one and my conclusion is that the
fifth location will always display the original "creation" location in the
Models and Add-ins dialog. Why is that?
But if you move the template to, let's say location #1, then the Models and
Add-ins dialog will display the correct information.

From what I have seen, if the template is in the fifth location, the Models
and Add-ins dialog always displays the original folder where the template
was when the document was created. This means Word stores that info
somewhere and can retrieve it if you place the template in the fifth
location....
I'll stop now, before my head blows... It's getting more and more absurd
like that Fifth element movie!

--
Cheers!
_______________________________________
Jean-Guy Marcil - Word MVP
(e-mail address removed)
Word MVP site: http://www.word.mvps.org
 
P

Peter Hewett

Hi JGM

I've been doing some tests using Word 2K (XP to follow).

METHODOLOGY

I seeded the following folders with the same template ("Template
Location.dot"):
F:\
F:\My Templates\
F:\My Templates\Base Folder\ [User Templates]
F:\My Templates\Test Documents\ [Workgroup Templates]
E:\Program Files\Microsoft Office\Office\

I created a document from the template in "F:\My Templates\" and saved this
document to "F:\".

RESULTS

1. Open document, attached to: "F:\"
2. Renamed "F:\Template Location.dot"
3. Open document, attached to: "F:\My Templates\Base Folder\"
4. Renamed "F:\My Templates\Base Folder\Template Location.dot"
5. Open document, attached to: "F:\My Templates\Test Documents\"
6. Renamed "F:\My Templates\Test Documents\Template Location.dot"
7. Open document, attached to: "F:\My Templates\"
8. Renamed "F:\My Templates\Template Location.dot"
9. Open document, attached to: "E:\Program Files\Microsoft Office\Office\"

NOTES

I don't have a "?:\Program Files\Microsoft Office\Office10\" folder even
though I have XP installed.

CONCLUSION

The Word search path for locating a template (lets call it the template
search path) is as follows:

1. The folder in which the document is stored
2. User Templates (Tools>Options>File Locations)
3. Workgroup Templates folder (Tools>Options>File Locations)
4. The folder containing the template the file was created from, if not one
of the above
5. ?:\Program Files\Microsoft Office\Office


Hope that's of interest + Cheers - Peter
 
E

EdC

Peter, Jean-Guy,

Thanks for your replies. I must admit I'm a bit confused, because I'v
read a lot of the posts on this board on this subject and I thought I'
understood what to do, if not how to do it.

When someone at my company creates a Word document using a templat
located on the network in the UK, then sends it to our office in th
US, the recipient opens the document, and Word goes off to find th
template stored on the network. This is fine, except that it take
time to open and the recipient finds this annoying. If I send
document to the US created using a template located on my C drive, th
document opens immediately.

The idea of adding a macro to the network template was to d
automatically what I could do manually. I could create a documen
using a network template then go in and remove the entry in th
Document template field under Tools>Templates and Add-ins. Wor
subsitutes the normal template, but the original formatting i
maintained
 
J

Jean-Guy Marcil

Hi Peter,

Except for point #4 (which I do not think I though of testing... thanks for
being thorough), we arrived at the same conclusions. I am glad to see that
it is not just my system that behaves that way.

Strange that you do not have an Office10 folder... How did I end up with
one?

Is Windows XP the OS for your Office XP?

--
Cheers!
_______________________________________
Jean-Guy Marcil - Word MVP
(e-mail address removed)
Word MVP site: http://www.word.mvps.org


Peter Hewett said:
Hi JGM

I've been doing some tests using Word 2K (XP to follow).

METHODOLOGY

I seeded the following folders with the same template ("Template
Location.dot"):
F:\
F:\My Templates\
F:\My Templates\Base Folder\ [User Templates]
F:\My Templates\Test Documents\ [Workgroup Templates]
E:\Program Files\Microsoft Office\Office\

I created a document from the template in "F:\My Templates\" and saved this
document to "F:\".

RESULTS

1. Open document, attached to: "F:\"
2. Renamed "F:\Template Location.dot"
3. Open document, attached to: "F:\My Templates\Base Folder\"
4. Renamed "F:\My Templates\Base Folder\Template Location.dot"
5. Open document, attached to: "F:\My Templates\Test Documents\"
6. Renamed "F:\My Templates\Test Documents\Template Location.dot"
7. Open document, attached to: "F:\My Templates\"
8. Renamed "F:\My Templates\Template Location.dot"
9. Open document, attached to: "E:\Program Files\Microsoft Office\Office\"

NOTES

I don't have a "?:\Program Files\Microsoft Office\Office10\" folder even
though I have XP installed.

CONCLUSION

The Word search path for locating a template (lets call it the template
search path) is as follows:

1. The folder in which the document is stored
2. User Templates (Tools>Options>File Locations)
3. Workgroup Templates folder (Tools>Options>File Locations)
4. The folder containing the template the file was created from, if not one
of the above
5. ?:\Program Files\Microsoft Office\Office


Hope that's of interest + Cheers - Peter


Hi Peter,

And, I believe there is a fourth location and a fifth location:

The fourth location is the folder containing the document itself. And
that one is priority one.
For the fifth, see at the end of my post...

I have just done some tests with Windows and Office XP:

I create a document from a template from the User folder;
Then save it somewhere (D:\);
Close Word;
Then I copy the template to the Workgroup folder;
Open my doc;
It is still attached to the user template;
Close Word;
Delete the template from the User folder;
Open my doc;
It is now attached to the template in the Workgroup Template;
I copy the template back to the User folder;
Delete the one form the Workgroup folder;
Copy the template to D:\ (Where my document is stored);
Open the document;
It is now attached to the template at D:\, not the available one in the
User folder.

I did all kinds of other tests, I even tried with the template at three
or four locations simultaneously.

Unless I have missed something; my conclusions are (Regarding the
priority order for attaching a template when loading a document):

1. Folder containing the active document
2. User Templates (Tools>Options>File Locations)
3. Workgroup Templates folder (Tools>Options>File Locations)
4. ?:\Program Files\Microsoft Office\Office10 (for XP)
and the fifth...
5. ?:\Program Files\Microsoft Office\Office (for XP)

This last one is very strange, Consider the following:
I create a document based on a template in one of the other four
locations, let's say User folder;
Then I close Word:
Move the template from the User folder to the fifth location;
Open the doc;
The Models and Add-ins dialog tells me my document is attached to a
template located in the User Folder, even if it is actually in that
fifth location (and does not exists anymore in the User folder)!

I did a lot of testing with that last one and my conclusion is that the
fifth location will always display the original "creation" location in
the Models and Add-ins dialog. Why is that?
But if you move the template to, let's say location #1, then the Models
and Add-ins dialog will display the correct information.

From what I have seen, if the template is in the fifth location, the
Models and Add-ins dialog always displays the original folder where the
template was when the document was created. This means Word stores that
info somewhere and can retrieve it if you place the template in the
fifth location....
I'll stop now, before my head blows... It's getting more and more absurd
like that Fifth element movie!

--
Cheers!
_______________________________________
Jean-Guy Marcil - Word MVP
(e-mail address removed)
Word MVP site: http://www.word.mvps.org
 
P

Peter Hewett

Hi JG

Maybe I'm the odd-one-out (it wouldn't be the first time!). I ALWAYS do
custom installs and I may have changed the target directory, although I can't
remember for sure!

Thanks for your input + Cheers - Peter
 
J

Jean-Guy Marcil

Hi there,

Same here, I always customized the installation (I do not want some software
install some stuff I will never use...), but I do not usually change the
target directory for heavy duty installs (large involved software like
Office, Visual Studio...) as I do not know the repercussions... So my
Office10 folder was certainly created by MS!

--
Cheers!
_______________________________________
Jean-Guy Marcil - Word MVP
(e-mail address removed)
Word MVP site: http://www.word.mvps.org
 
C

Charles Kenyon

I have templates with AutoNew macros that (at the end of the macro) attach
the document to normal.dot. This works fine when (other than the AutoNew
macro) the template holds the format and basic text. The text pulls in the
styles. It wouldn't work if you wanted custom AutoText or toolbars.
--

Charles Kenyon

See the MVP FAQ: <URL: http://www.mvps.org/word/> which is awesome!
--------- --------- --------- --------- --------- ---------
This message is posted to a newsgroup. Please post replies
and questions to the newsgroup so that others can learn
from my ignorance and your wisdom.
 
C

Charles Kenyon

It creates an Office10 folder if there is another version of Office
installed first. Don't know if it does it on a clean install.
--

Charles Kenyon

See the MVP FAQ: <URL: http://www.mvps.org/word/> which is awesome!
--------- --------- --------- --------- --------- ---------
This message is posted to a newsgroup. Please post replies
and questions to the newsgroup so that others can learn
from my ignorance and your wisdom.
 
J

Jean-Guy Marcil

Hi Charles,

You are right, when I installed Office XP on this computer at work, we
bought the upgrade version. The computer was brand new, so I had to install
the previous version first to get the upgrade to work. But Office 2000 was
also an upgrade... so I had to install Office 97, which was also an
upgrade.... My boss still had her Office 95 3 inch diskettes, all 20 of
them... I took me over an hour to install Office XP! But still, as it was an
upgrade, it is strange that it did not just overwrite the Office folder
content instead of creating an Office10 folder...

--
Cheers!
_______________________________________
Jean-Guy Marcil - Word MVP
(e-mail address removed)
Word MVP site: http://www.word.mvps.org
 
C

Charles Kenyon

I suspect that if you do a defective install of Office 2000 and then upgrade
over that it will work. I know this works for me with Dragon Naturally
Speaking which I started at Version 2 and upgraded through versions 3, 3.5,
4, 5 and now 6. Versions 2-5 won't even run on Windows XP!
--

Charles Kenyon

See the MVP FAQ: <URL: http://www.mvps.org/word/> which is awesome!
--------- --------- --------- --------- --------- ---------
This message is posted to a newsgroup. Please post replies
and questions to the newsgroup so that others can learn
from my ignorance and your wisdom.
 
J

Jean-Guy Marcil

Hi Charles,

Thanks for the tip,

But I am about to do a major overhaul of my system. I will be using Virtual
PC to create from 4 to 6 OS... So I'm off to the shop to buy anew hard disk
and loads of RAM! Then I will install full Office versions..., so I will be
back to the "norm".

--
Cheers!
_______________________________________
Jean-Guy Marcil - Word MVP
(e-mail address removed)
Word MVP site: http://www.word.mvps.org
 
J

Jean-Guy Marcil

Hi Ed,

Just reassigned the attached template when you create a document based on
the template using this macro:

'_______________________________________
Private Sub Document_New()

ActiveDocument.AttachedTemplate = ""

End Sub
'_______________________________________

Paste this macro in the ThisDocument module of your templates. Every time a
document based on those templates will be created, it will inherit the
content and the styles from the Network template and then be attached to the
"Normal.dot" template. Be aware that if your templates have other macros,
customized toolbars and some AutoText entries, they will be lost to those
documents thus created.

--
Cheers!
_______________________________________
Jean-Guy Marcil - Word MVP
(e-mail address removed)
Word MVP site: http://www.word.mvps.org
 
P

Peter Hewett

Hi Ed

This is something you shouldn't need to do!

There are potentially two causes for this problem.

1. Word can't find the template (at all) but the template search path and
folder structure is complex enough that this search slows Word down.

2. The second is that Word is going out over your nextwork from the US to
locate the template in the UK.

As you've seen from earlier in this thread Word does not assign a high
priority to locating a documents attached template in it's original folder,
in fact as you've seen that this is the 4th place Word searches, not the
1st!!!

So you can exploit this behaviour to resolve your problem. The easy way out
is to duplicate the necessary templates on the US server, preferably in
whatever the mapped "Workgroup Templates" path is. As Word is going to use
this location in preference to the location of the template used to create
the document.

Most organisations I've worked with have a synchronisation procedure in
place to take care of issues like this. If so just get your templates
synced out whenever you update them.

HTH + Cheers - Peter
 
E

EdC

Peter said:
*Hi Ed

This is something you shouldn't need to do!

There are potentially two causes for this problem.

1. Word can't find the template (at all) but the template search pat
and
folder structure is complex enough that this search slows Word down.

2. The second is that Word is going out over your nextwork from th
US to
locate the template in the UK.

As you've seen from earlier in this thread Word does not assign
high
priority to locating a documents attached template in it's origina
folder,
in fact as you've seen that this is the 4th place Word searches, no
the
1st!!!

So you can exploit this behaviour to resolve your problem. The eas
way out
is to duplicate the necessary templates on the US server, preferabl
in
whatever the mapped "Workgroup Templates" path is. As Word is goin
to use
this location in preference to the location of the template used t
create
the document.

Most organisations I've worked with have a synchronisation procedur
in
place to take care of issues like this. If so just get you
templates
synced out whenever you update them.

HTH + Cheers - Peter
*
This sounds a good plan, but if I ask the US to install the U
templates in their mapped Workgroup Templates path, then wouldn't i
mean that when they go File>New in Word, they get a load of template
that they don't need, and I think probably don't want cluttering thing
up
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top