I have a word template in my startup folder. This has a DocumentChange event which fires whenever the focus switches to a
different word document. It is used to modify a number of application specific toolbars.
The code called from the
event changes CustomizationContext to the attached template and to the Global template containing the event code, and enables
/ disables various toolbar controls. It manipulates the .Saved property of the templates so that it doesn't "dirty" them with
This code works perfectly on Word 2000 and Word 2002, but on Word 2003 it generates an infinite loop
whenever the user vists the header of a document. Single stepping the code I can see that the code runs to completion and
then the event immediately fires again. This is not a recursion - it does complete each time and exits at the final End Sub.
It is almost as though there is an event queue waiting for the macro to exit. It only happens if the user double clicks in
the header of a document (or possibly a footer, I haven't checked this).
I tried setting a boolean variable at the
beginning of the event routine and immediately exiting if I find it true, but since this is not recursion it didn't help. I
also tried inserting a DoEvents before exiting to see if that helped, but it still waits till the Exit Sub before starting
again! I even tried disabling events by putting
Set AppEvents.App = Nothing
Set AppEvents.App = Word.Application
at the beginning and end of the event code, but this didn't help either.