PDA

View Full Version : AutoExec Macros in Global Templates



TonyJollans
09-23-2005, 10:44 AM
Following on from another thread I found out one or two things I didn't know about AutoExec macros so I have read up and experimented. You probably all know this but an AutoExec in a global Template runs when the Template is loaded.

While playing with this I did the following:




Renamed Normal.dot so that I got a brand new clean one - this isn't necessary, it just shows that nothing I have in Normal is interfering with anything.
Removed all my existing global Templates - again just so they didn't interfere.
Created two new blank global templates in my startup folder - Temp1.dot and Temp2.dot
Closed and opened Word
Opened one of the templates, Temp2, for editing and added an AutoExec macro
Sub AutoExec
Msgbox ThisDocument.Name
End Sub

Closed Word - when prompted to save changes to Temp2, replied Yes
Opened Word - saw message box "Temp2.dot" as expected
Opened the other template, Temp1, for editing and added the same simple Autoexec macro to it.
Closed Word - when prompted to save changes to Temp1, replied Yes
Was then prompted to save changes to Temp2, even though I hadn't opened it for editing.
Replied No
Opened Word and saw two message boxes "Temp1.dot" and "Temp2.dot" - as expected.


Next I repeated the above, except that in the next to last step, I replied Yes to save changes to Temp2
Opened Word again. This time I only saw one message box, "Temp1.dot".
The macro in Temp2.dot was completely disabled - the text was there in the module in the VBE but the macro was not - it didn't autorun, it wasn't available via ALt+F8, etc. I could add new procedures to the module and they all worked OK, but the AutoExec just, for all practical purposes, wasn't there.

Now, I don't know any way to so totally disable a macro. With a lot of messing about, I can make it come back but I'm not entirely certain of a consistent set of steps to do it. But what has happened?

Is this something else I don't know that I really should - or is there something funny going on here?

sandam
09-23-2005, 03:40 PM
it might be that the process didn't entirely clsoe properly. I know that if outlook has word running as the default editor there is an instance of Word constantly running and it can reek havoc at times. It could also be that although you had closed Word, the process might still have been running which could explain the results you got.

Just my ?0.02, as was pointed out in the thread this follows from I can get it wrong (very wrong but I'll admit it when I am :P)

TonyJollans
09-23-2005, 04:02 PM
Thanks, sandam, but everything closes cleanly and I can do this repeatedly on both Word 2000 and Word 2003 without anything else running.

Regardless of how Word shuts, and without having Temp2 open for update, Word is prompting me to save changes that I can't possibly have made - and changes of a type I don't know how to make.

MOS MASTER
09-23-2005, 04:19 PM
Thanks, sandam, but everything closes cleanly and I can do this repeatedly on both Word 2000 and Word 2003 without anything else running.

Hi Tony, :hi:

Very interesting. I've taken the test and I can duplicate it step by step (Office 2000) no time to test on other versions. (Expect differences as usual) And remember 2000 has a differences in template automacros. (Can't find the article by MS right now but look it up)

I've been using multiple Automacro's in global templates for a long time and I know you can use more then one autoexec.

What I didn't know was that you get a save question from temp2 that you didn't edit while putting the Automacro in temp1.

And I sure as hell didn't know you could disable the macro in temp2 by pressing yes at the save prompt. Very, very interesting!!! :yes (I will test for sure on all versions later)

I guess I never found this out cause I always test like I told you before in a Clean Word environment. (Like you described in your prefix, New Normal and NO globals loaded)

Thanx for sharing this Tony

Need to test more on all versions. (But you've done 2000/2003..so it must be a build in mechanisme)

O well I'll find out the differences soon enough.

Later buddy. :whistle:

fumei
09-24-2005, 05:13 AM
Tony, try the experiment again. But this time, try it with renaming the two .Dot files in Startup. Make it so they are parsed in reverse order. Rememeber that global .dot files are NOT loaded, just parsed for procedures. Pointers to those procedures are created.

fumei
09-24-2005, 05:32 AM
Oh, and you may want try using Selection.Typetext Text = "procedure name fired" & vbcrlf - instead of Messageboxes. That way you get a list of the fired procedures, and the order they fire.

TonyJollans
09-24-2005, 09:41 AM
Thanks Gerry,

Yes, it makes sense not to use message boxes because they can sometimes interfere with other startup processing.

As for the rest, I have tried renaming and switching order, I have tried removing the template which works, I have tried unloading and reloading the template, I have opened the template for editing, I have tried to find a way to explicitly run the macro, I have tried porting the template to another machine, I have tried recompiling the project, and in no case have I been able to run it - it just isn't recognised as being there.

MOS MASTER
09-25-2005, 03:35 PM
The topic is very interesting and I'm but all to sorry I don't have the time right now to test with you. (I'd really love to)

Keep it up guys! :yes