Hi Jacque:
Jacques said:
Hi John. The global template into which I tried to put an AutoOpen macro
was in fact in my Word Startup folder. But I'm surprised that you say a
global template MUST be there. In Tools>Templates and Add-ins there are
the options (a) to attach a document template, or (b) to add a global
template which is not already loaded. I just tried adding (as a global
template, not the document template) a template from outside the Startup
folder, and it seemed to work OK. Does Word use the term "global
template" in two different senses, sometimes including a template added
after start-up and sometimes not? Does a global template added after
start-up (if such a thing exists) behave differently from one loaded on
start-up?
Ah! My mistake. I neglected to mention that you can load Global Templates
using that dialog. I don;t use it, because it can be unreliable (if the
gloabl template is not found on next Word startup, it will not be loaded,
and then won't load correctly in future. So I like to put them all in
Startup so I know where they are
The distinction is that a Global Template (Whether loaded from Startup or by
Templates>Add...) is loaded by the application, before any documents load,
and is available to all documents that are open.
The Attached Template is loaded AFTER the document which calls it loads, and
resources within it are NOT available to any other documents that may be
open (unless they Attach the same template).
Whereas the NORMAL template is either loaded or created by the application
before anything else loads, and its resources are also available to all open
documents.
Normal is basically the "Lender of Last Resort" which is always guaranteed
to be present and is the last place Word looks for things. So you can have
an AutoOpen in Normal and one in the Global template and one in the Attached
Template, all with the same name. The one that runs will be the one in the
Attached Template.
This is worth remembering, although it's risky, it can be useful: You can
have multiple macros of the same name in context, provided they are in
different templates. Only ONE of them will AUOT-run: the one in closest
context.
You CAN override this context by explicitly calling the macro you want from
a named template, but for god's sake DON'T -- nobody will be able to
maintain your code -- including YOU!!
And don't go spending money on books on VBA for the Mac. All VBA on the Mac
will go away in a few months! Spend your money on AppleScript books.
Sorry, I don't understand that. It was the same code that worked OK if
put in the Normal template. And it was the only macro I had put in the
global template. But I'm certainly confused about "macro projects",
"modules", "procedures" etc. The Missing Manual isn't much help on this,
but I've ordered a couple of Woody Leonhard's books on Winword 2000
which I hope will make things clearer.
I know the "Missing Manual" series is highly revered, but I found that the
thing that is mainly missing in my copy of one of them is "content"
The error "ambiguous name" does not necessarily mean the name of a macro, it
can be the name of anything, such as a variable. The VBA compiler compiles
the whole Project: names must be unique within the project.
A "Project" is a "Template" for our purposes. A "Module" is a a collection
of macros: the thing that appears in the left column of the VBA Editor:
"NewMacros is an example, the default module created when you record things.
A "Procedure" is a single macro. "Sub" stands for "Subprocedure". There
are several other flavours: Functions are the one you will see most often.
Cheers