VB Code .dots vs .docs

L

Lenny

Can someone please respond and clarify? Can you write/copy vb code into a
Word (.doc) vb editor? and.... will the code remain in the Editor when the
..doc is saved as another .doc iteration?

I work in a network environment and the protected forms (Word master
templates) .dot's are stored on the network. Users access the templates thru
Words "File New" where custom tabs give the employee access to all the
companys electronic forms.

Many of the .dot's have code to automate, or perform functions. I struggled
for years trying to figure why sometimes the customizations worked and then
didn't. Then, came across a MVP article that explained a lot of things
(light went on in the tower!) However.... have been running on assumption
that a copy of the .dot had to be stored in the Office or preferably the Word
Startup folder to make the code available for any .doc created off the master
since the .dot did not pass the code on to the .doc, rather would make it
available.... then two things happened, I downloaded an article that said
that code could be placed into the .doc editor and then a document (.doc)
from an engineer that had come from one of our customers fell into my hands
that had a ton of code in the vb editor and it WORKED!! I saved the .doc as
another .doc and the code was in the child document.... What am I missing
here?

My IT department is not real happy with placing a .dot into the Startup
folder as our equipment is leased and we're talking thousands of machines
that are getting swapped out all the time.

Any assistance in better understanding how .dot's spread the wealth is
really, really appreciated...:) lenny
 
J

Jay Freedman

Hi Lenny,

It's really pretty simple...

If you use the File > New dialog (or the equivalent Documents.Add in a macro) to
base a new document (.doc) on a template (.dot), and the template contains code,
the new document does _not_ automatically get a copy of the code. The template
is simply "attached" (linked) to the document, so every time you open the
document its template is silently opened in the background to make the macros
available -- assuming that template is still available (otherwise Normal.dot
gets attached).

But you _can_ save macro code in a document by doing it manually (i.e., not
through the File > New mechanism, but by opening the editor and pasting in the
code, or writing it there from scratch).

And once you have a document that contains code, the File > Save As mechanism
makes a copy of the whole document, including the code, under the new name.

Having code in a document really isn't a recommended setup, mainly because
that's a favorite way of spreading viruses. When the macro security level is set
to anything except Low (which should be called Off), Word complains with a big
nasty message box when you try to open a document containing code -- or it just
disables the macros without notice. That's usually enough to scare the average
user into not opening the document.

--
Regards,
Jay Freedman
Microsoft Word MVP
Email cannot be acknowledged; please post all follow-ups to the newsgroup so all
may benefit.
 
L

Lenny

Jay: my thanks - that really helped clear up some misunderstandings and
explains why the code in the .doc I was sent worked without benefit of having
a .dot linkage.... is there then, any way to ensure that the user always has
access to the code? Also - how far down the 'save', 'save-as' line does the
..doc recognize the master .dot that it was created from? Is there a point
where a document will no longer recognize the template in the Startup folder?
As with anything on the computer, most people just keep doing a 'save' as
when they need a copy instead of taking a new document.

Could a macro be written to do the following: when the user accesses a coded
template on the network and uses the 'file new' mechanism, upon opening, the
file (.dot) will automatically save a copy of itself to the Word Startup
folder of the user (think network user). It would also need to be able to
check the folder for an existing copy, verify a reference number and delete
the file in the folder if it is an earlier revision number. This is the only
way I can think of to get the .dot where it seems to need to be without
having 1000 users go thru the process of saving a copy there. and... if this
was possible - could someone help with code.... (If this is beyond what the
MVP's normally help with, please let me know -- I would be happy to purchase
the services for the code in this project, as it's that important.) I've
written a lot of code but mostly simple stuff, and this is beyond any of my
code skills.

Again - thanks to you and all the other MVP's who are willing to help
Regards... Lenny
 
J

Jonathan West

Lenny said:
Jay: my thanks - that really helped clear up some misunderstandings and
explains why the code in the .doc I was sent worked without benefit of
having
a .dot linkage.... is there then, any way to ensure that the user always
has
access to the code?

Send the user the template.
Also - how far down the 'save', 'save-as' line does the
.doc recognize the master .dot that it was created from?

Whenever you create a document, it is always attached to a template.
Similarly, whenever Word opens a template, Word always tries to attach the
same template that was attached before. if you move a document between PCs,
that isn't always possible, but Word does its best. It looks in the
following locations for a template of the same name as the original

1. The original location of the template
2. The User Templates folder
3. The Workgroup templates folder
4. The folder containing the document itself

If a template of the appropriate name isn;t in any of those locations,
Normal.dot gets attached instead.
Is there a point
where a document will no longer recognize the template in the Startup
folder?

Ah, the startup folder is a bit different. If a template is in the startup
folder, Word loads the template as an add-in. It isn't attached to any
document, but it is loaded so that its macros and toolbars are available.

Generally, if you want a macro to be available whatever document you have
open, put the macro into a template in the startup folder. If your macro is
specific to a particular document type, put it in the template for that
document type.
As with anything on the computer, most people just keep doing a 'save' as
when they need a copy instead of taking a new document.

Could a macro be written to do the following: when the user accesses a
coded
template on the network and uses the 'file new' mechanism, upon opening,
the
file (.dot) will automatically save a copy of itself to the Word Startup
folder of the user (think network user). It would also need to be able to
check the folder for an existing copy, verify a reference number and
delete
the file in the folder if it is an earlier revision number. This is the
only
way I can think of to get the .dot where it seems to need to be without
having 1000 users go thru the process of saving a copy there. and... if
this
was possible - could someone help with code.... (If this is beyond what
the
MVP's normally help with, please let me know -- I would be happy to
purchase
the services for the code in this project, as it's that important.) I've
written a lot of code but mostly simple stuff, and this is beyond any of
my
code skills.

It sounds like what you need is an installer. I create templates for
customers all the time, and I use the following program to create installers
so that the templates get into the correct locations.

Advanced Installer
http://www.advancedinstaller.com/

The free version is quite adequate for the purpose of getting a few
templates copied into the correct locations, and it isn't hard to learn.
 
L

Lenny

Lenny wrote: Jonathan, this has been one of the best and informative threads
.... I picked up some really good information. Some clarification to some of
your responses please...

It looks in the following locations for a template of the same name as the
original
1. The original location of the template (in my situation where the master templates are stored on the network, is that their 'original' location?)
2. The User Templates folder (assume this is the 'Template' folder on the users computer. Does placing a copy of the master .dot in the Template folder act or do the same as placing it in the Startup folder?)
3. The Workgroup templates folder (still unsure of this concept, is this a template folder created for a workgroup on a network?)
4. The folder containing the document itself (any folder on a users computer where they might save a copy of the .dot? Do I assume that if a copy of a master .dot is placed in say, the users MY DOCUMENTS folder and the user opens the template and saves a document off the template to another location on their computer, that the document (.doc) can access the code and toolbars as long as the user does not move the master .dot from MY DOCUMENTS?) Sorry - so many questions - so little contact with those that have the answers!

Jonathan - I have around a thousand master templates stored on the network
for all aspects of the company - from finance, to engineering and these are
accessed from all over the globe... there is no way I could send employees a
copy of the .dot :)

From the information provided in this thread, it seems I have some
evaluating to do regarding the vehicle of the code. We share templates
between major companies all over the world and I need to come up with
something that will work everytime, for everyone. Thank you for the
information regarding the Installer. I will most definitely check it out as
well as your site..... regards, Lenny
 
J

Jonathan West

Lenny said:
... I picked up some really good information. Some clarification to some
of
your responses please...

It looks in the following locations for a template of the same name as the
original

Yes. But beware of templates stored on a network. There is a bug in Word
such that, if you have a document based on a network template, and you email
the document to someone who doesn't have access to that network location,
when they open the document Word can wait several minutes before it finally
gives up on any hope of getting a response from that network location and
decides to attach normal.dot instead and finally display the document to the
user. There is a hotfix available from Microsoft, but particularly if you
send documents outside your own organisation, you cannot assume that
everyone has the hotfix installed. For this and several other reasons, I
recommend always that templates are stored locally.


If you go to Tools, Options, and click the File Locations tab, you will see
the location of the User Templates folder. By default it is C:\Documents and
Settings\<username>\Application Data\Microsoft\Templates. (The default path
is different in Windows Vista).

The Startup folder has an entirely different purpose. If you place a
template there, its macros are available always for all documents, whatever
template they are based on.

The Tools, Options File Locations dialog has a Workgroup templates folder
that you can define. By default it isn't set to anything at all.
Unfortunately, its usefulness is somewhat limited as a result of the network
templates problem I described above.

The same folder where they save the document itself. Can be anywhere.

Yes, because the current location of the template (wherever it is) is saved
when you save the document, and will be remembered when you next open the
document.
Jonathan - I have around a thousand master templates stored on the network
for all aspects of the company - from finance, to engineering and these
are
accessed from all over the globe... there is no way I could send employees
a
copy of the .dot :)

If you have a thousand templates, then I suggest a bit of rationalisation
might be in order. If you are planning a move to Office 2007 any time soon,
it would be good to do that rationalisation before you make the upgrade, so
that you have fewer templates to convert.

Precisely how you would go about that is beyond the scope of an answer here.
The Word MVPs website lists several MVPs (including me) who take on paid
consultancy work. If you are interested in going that route, take a look
here http://word.mvps.org/AboutMVPs/index.htm for a list of the MVPs, and
from there you can look at the details of individual MVPs and see if they
take paid consultancy.
From the information provided in this thread, it seems I have some
evaluating to do regarding the vehicle of the code. We share templates
between major companies all over the world and I need to come up with
something that will work everytime, for everyone. Thank you for the
information regarding the Installer. I will most definitely check it out
as
well as your site..... regards, Lenny

In that case, I hope that you have got yourself a code-signing certificate
which you apply to your templates, otherwise in most cases the macros will
be prevented from running by the customer's security settings.
 
L

Lenny

Lenny here: Jonathan, my thanks for sharing this information. Again, this
has been a great learning experience and hope it provides such for others.
Will take your recommendation for consultancy when we migrate to 2007.
regards
 

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