Global toolbars

K

Kenton

Why, when removing a toolbar (i.e. Formatting toolbar) within a custom word
template does it cause that toolbar to be “Globally†removed even if a
normal.dot document is opened?

How can I overcome this problem? I have a template that closes all open
toolbars, only viewing a custom toolbar. Currently I am writing the
CommanBars visible status to a text file to be able to restoring the toolbars
when the template document is closed. Is there a better way?
 
T

Tony Jollans

Changes to Toolbars are applied within a CustomizationContext; by default it
is set to NormalTemplate (i.e. global). If you don't specify otherwise, the
customisation you apply will be done to the Normal template and apply
wherever that applies (globally). If you specify a CustomizationContext of
ActiveDocument.Attachedtemplate, say, the changes should only apply to
documents using that template.
 
L

Lene Fredborg

I suppose you mean “hide†when you say you “remove†toolbars.

The default behavior is as follows:
When you open a document or create a new document, it will appear with the
same toolbar setup as the document that was active beforehand. If no
documents were open, it will appear with the toolbar setup of the last
document that was open (in the same or the previous Word session).

Therefore, you are right – you need something to control the toolbars in
order to revert to the user’s original setup.

Does your code also include code that closes the document in which the
"normal" toolbars are hidden?
In that case I think I have an idea you could use.

--
Regards
Lene Fredborg - Microsoft MVP (Word)
DocTools - Denmark
www.thedoctools.com
Document automation - add-ins, macros and templates for Microsoft Word
 
K

Kenton

Hello Tony

Thank you for your suggestion. However the CustomizationContext does not
solve the problem. I have the following code in my templates open event.


Private Sub Document_Open()
Set OldCuzContext = Application.CustomizationContext 'Get

CustomizationContext = ActiveDocument.AttachedTemplate 'Set
Set TempCuzContext = Application.CustomizationContext

CommandBars("Standard").Visible = False
MsgBox TempCuzContext

CustomizationContext = OldCuzContext 'Restore
MsgBox OldCuzContext

End Sub

But if I close the document then open another document the Standard toolbar
does not view.
 
K

Kenton

Hello Tony

Hello Lane, thank you for your reply. Yes I did mean hide. My problem is
exactly as per your "default behaviour scenario" description.

I am not to sure if I understand your last question:

1. My code does NOT close the document except if the user clicks on close.
(There is NO ActiveDocument.Close code)

2. My template does have a close event.

I even record the toolbar statuses when the document is opened then restore
them back when the document is closed. Although this works great Word does
not have a “WindowsActivate / WindowsDeActive†event to be able to control
the behaviour of active documents.
 
L

Lene Fredborg

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
 
K

Kenton

Hello Lane, Thank you for your process on creating a new document to be able
to “record†the toolbars. I will give it a try but for now I will stick to my
text file as sugested.

Please give me more information regarding the DocumentChange event remember
I am using Word 2003.

Thank You
 

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