AutoExec fails - recompile rectifies it

M

Mick Hardy

I have an unusual and bewildering problem. I have a Word XP template
installed into the Startup folder of Word. After several security
updates were applied to the Network, my template no longer worked
because the Autoexec macro, which assigns the application object to my
event class, does not execute. Opening the template and recompiling
the code, fixed the problem. There are no references as everything is
late bound.

I rebuilt the installation package with the newly compiled template
(114KB instead of 112KB) and everything seems to be fixed. My worry
is, will this problem come back with any further upgrades?

I've seen this same problem give the "Could Not Open Macro Storage"
bug in a third party global template. I recompiled the third party
template and the problem went away.

What is Word doing during compilation that could be causing this
behaviour. The PCs are lockd down with a billion different policies.
I can't work out exactly what updates were installed. Any thoughts at
all would be greatly appreciated. I've exhausted my short list of
ideas.
 
H

Howard Kaikow

Without analyzing your code, I cannot suggest a sure fix other than to
suggest that you make sure the class is instantiated correctly before the
AutoExec continues executing.

I had a sort of similar problem with Excel.
In Excel, when you open a workbook, Excel checks to see whether any cells
need to be recalculated.
It does this BEFORE even the workbook open event is invoked.

Conceptually, you'd think that one would could on the workbook_open event
running before anything else, but it does not.
Likely the same problem with an AutoExec is a template in the Startup
directory.
Perhaps, it would work better if the AutoExec was in the Normal template/

So a solution was to test whether the class had been instantiated BEFORE any
code called the class.
If not, then I call code to instantiate the class.
 
M

Mick Hardy

Thanks for your detailed reply. Let me clarify a little. The problem
is caused by the AutoExec procedure not firing. This macro
instantiates the class and assigns the Word.Application object to the
class. Because the AutoExec macro never fires, my code cannot respond
to the New event (which checks for a corporate doc) and therefore my
code does not display the relevant form stored in an external VB6 DLL.
The code is not relevent, but I've posted it anyway.

All of my template functions repeat the work done by the AutoExec
macro if it has not ben completed. This was to workaround a separate
documented MS bug where AutoExec does not fire if Word is Outlook's
editor. (MSKB 209978)

With the new issue, AutoExec will not fire until I open the VBA code
editor and compile the template. After the recompile, AutoExec fires
as expected. The problem occurs when the user double clicks on one of
our templates and the relevant form is not displayed. The issue is
currently fixed but I'm worried about what MS did to break it in the
first place.

This happened on Windows XP in both Word 2000 and Word 2002. It may
be a Windows XP update or security patch that caused it, as the
problem has not occurred on my Windows 2000 box.

Public Sub AutoExec()

'Constant holds the procedure name for the error handler
Const strSig = mstrModule & "AutoExec"

'***********************************************************************
'Purpose: Initialises the corporate template
'***********************************************************************

On Error GoTo ErrHandler

'Generate a new instance of our doc control class
Set mclsDC = New clsDocControl

'Set the class event handler to the Word application so we
'can listen for and respond to particular events
Set mclsDC.App = Application

Exit Sub

ErrHandler:

LogError strSig

End Sub
 
H

Howard Kaikow

Your description of the problem is consistent with my posting.
Please try the solution I suggested.
 
M

Mick Hardy

Thanks heaps for your interest Howard. I'm still a little unsure
exactly what you are suggesting. I am very reluctant to put any code
in the Normal template. I treat Normal.dot as the user's personal
template. They can do with it whatever they like but I don't touch
it. Are you suggesting ensuring the Word.Application object is fully
instantiated and, if so, how? There is no "ReadyForUse" poperty that
I'm aware of. My class is instantiated by the line of code before I
assign the Application object so I know it exists.

Maybe, as you mention with Excel, the new document is created before
my AutoExec macro fires. If this is the case, why would my code ever
work and how do I fix it?

I think the crux of the problem is something to do with the
re-compile. Why would re-compiling my Global template with zero code
changes suddenly enable the AutoExec macro again? After the code in
my global template has been re-compiled, it always works as expected.
 
H

Howard Kaikow

In order to attempt to solve your problem, I'd have to analyze your code.
See my url below for the services I offer.
 
M

Mick Hardy

In order to attempt to solve your problem, I'd have to analyze your code.
See my url below for the services I offer.

Thanks for your concern but this is not the place to advertise your services.
 

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