About <Word does not have a “WindowsActivate / WindowsDeActive†event>:
Word has a DocumentChange event. It occurs when a new document is created,
an existing document is opened, or another document is activated.
Below, I will try to explain what I was thinking of as a possible solution.
However, if your current solution works, I think it is better and more
“clean†than my alternative (and I think I would have done something
similar…). My idea was to try finding a method that would let Word itself
“remember†the toolbar setup instead of writing the toolbar setup information
to a text file. The main principles of my idea:
1. In your code, keep track of “your document†(the one in which the closing
of toolbars is needed), e.g. Set oDoc = ActiveDocument.
2. Before you run code that changes the toolbar setup, you could create a
document. Make sure you keep track of the document, e.g. Set oDocTemp =
Documents.Add)*. This document will be used to “remember†the user’s current
toolbar setup (according to the default behavior described in my previous
post).
3. In your code, activate “your document†again. Run your code that changes
the toolbar setup.
4. As part of the code that runs when you close “your documentâ€, make
oDocTemp the active document.
5. Close “your document†without activating it again.
6. Now close oDocTemp without saving it.
Thereby, the toolbar setup from oDocTemp should be in use again. I do not
guarantee that it will work as you wish. And problems may occur. For example,
the user may close oDocTemp (and if you make the document invisible when
creating it, the toolbar setup will not be “rememberedâ€).
* If a document was open before you open “your documentâ€, you would not need
to create a new document as described above. You could instead make sure to
activate the “old†document before your code closes “your documentâ€.
--
Regards
Lene Fredborg - Microsoft MVP (Word)
DocTools - Denmark
www.thedoctools.com
Document automation - add-ins, macros and templates for Microsoft Word