Hi Marco:
This question is really worth a novel: something the size of War and Peace
should just about cover it
First: You said "Menu Bar": we don't have those. It's either a "Menu" or a
"Tool Bar", and the distinction is important to the answer. If you are
manipulating them programmatically, they're both called Command Bars", but
that's another dissertation.
I am going to assume it's a "Tool Bar" that you are discussing.
The usual cause of the problem is "Context Ambiguity." You have saved to a
Global Template. Chances are, the Normal Template on at least one of the
machines contains a toolbar of the same name.
Whether it appears or not depends on a binary addition of all of the various
states of that toolbar in all of the various templates that are in context
at the time the Application, and/or the Document, launches.
Toolbars can be in either the Application context or the Document context.
If they are in the Application context, the instance that appears must
reside in the first global template to load (usually: Normal template).
If the toolbar is in the Document context, it will appear only if it is
contained in the last document template to load.
I have long since given up trying to predict the behaviour of toolbars with
multiple documents open in multiple windows across both the application and
the document contexts. Instead, I use the following code to explicitly
force the toolbars I want to be visible. This code has proved reliable for
the past five years.
A couple of comments: There is a bug in later versions of MacWord that
cause the RowIndex and Left statements to be silently ignored, but they work
and they're valuable on the PC.
The ResetToolbars macro exists from the days when I used to run different
code on document close. I added condition statements to the SetToolbars
routine that mean I do not need that any longer and usually simply call
SetToolbars for both open and close.
If you run this code unchanged, be sure to include user buttons for the
ToggleWeb and ToggleReviewing macros: the SetToolbars macro disables these
two toolbars. Once it has run, there is no other way for the user to
display those toolbars if he needs them. On the Mac, the user will
definitely need the Web toolbar because that's the only way to open an HTML
file in MacWord.
Hope this helps
Option Explicit
Const CustomerStandard As String = "John Standard"
Const CustomerFormatting As String = "John Formatting"
Const DefaultStandard As String = "Standard"
Const DefaultFormatting As String = "Formatting"
Sub AutoExec()
Call SetToolbars
End Sub
Sub AutoOpen()
Call SetToolbars
End Sub
Sub AutoNew()
Call SetToolbars
End Sub
Sub AutoClose()
Call ResetToolbars
End Sub
Sub AutoExit()
Call ResetToolbars
End Sub
Sub SetToolbars()
' Brings up Customised toolbars
' Copyright 19 May 2003 by John McGhie
' McGhie Information Engineering Pty Ltd
' This macro tests for the presence of customised toolbars available
' to the active document, and displays them if present.
' Otherwise, it displays the personal customised toolbars.
' Constants provide a simple way of changing toolbar names in a single place
' The following four strings are all you need to change
' when moving from customer site to customer site
Dim aToolbar As CommandBar
Dim tbStandard As CommandBar
Dim tbFormatting As CommandBar
Dim tbCustStd As CommandBar
Dim tbCustFormatting As CommandBar
Dim ToolRowIndex As Integer
Dim MessageString As String
If Application.Documents.Count < 1 Then
' The user can leave us in a state where there are no active documents. If
' they do, we must not try to manipulate toolbars, otherwise we get an
error.
Set tbStandard = Application.CommandBars("Standard")
Set tbFormatting = Application.CommandBars("Formatting")
For Each aToolbar In Application.CommandBars
' First, enumerate the CommandBars collection to make sure the
' customer toolbars are available. If they're not, the code
' would emit a runtime error we want to trap and handle.
With aToolbar
' If the toolbar is already visible, it will not be enabled
' If it is not enabled, the code throws an undefined error in Wd97
If .Enabled = True And .Protection = msoBarNoProtection Then
Select Case .Name
Case CustomerStandard
Set tbStandard = aToolbar
Case CustomerFormatting
Set tbFormatting = aToolbar
Case "Web", "Reviewing"
If .Visible = True Then .Visible = False
If .Enabled = True Then .Enabled = False
Case "HDK"
aToolbar.Visible = True
.RowIndex = 9 ' Docking order
.Left = 0
Case Else
aToolbar.Visible = False
End Select
End If
End With
Next aToolbar
' Now we display whatever we found
With tbStandard
.Visible = True
.RowIndex = 8 ' Docking order
.Left = 0
End With
With tbFormatting
.Visible = True
.RowIndex = 9 ' Docking order
.Left = 0
End With
End If
GoTo alldone ' Exit the macro without running the error code
ErrorNotFound: ' Error handler
MessageString = "One or more of the customised toolbars are missing. " _
& vbLf & vbLf & "Ask Help Desk to restore them, or disable the macro. "
' Be kind, tell the user which ones are missing
If tbStandard = "" Then MessageString = MessageString & vbLf & vbLf &
DefaultStandard & " is missing."
If tbFormatting = "" Then MessageString = MessageString & vbLf & vbLf &
DefaultFormatting & " is missing."
MsgBox MessageString, vbExclamation + vbOKOnly, "Toolbar Macro"
alldone:
End Sub
Public Sub ResetToolbars()
' Restores Standard toolbars
' The user can leave us in a state where there
' are no active documents
If Application.Documents.Count < 1 Then End
Call SetToolbars
End Sub
Sub ToggleWeb()
CommandBars("Web").Enabled = Not CommandBars("Web").Enabled
End Sub
Sub ToggleReviewing()
CommandBars("Reviewing").Enabled = Not CommandBars("Reviewing").Enabled
End Sub
Sub EnableReviewingToolbar()
With ActiveDocument.CommandBars("Reviewing")
If Not .Enabled Then .Enabled = True
If Not .Visible Then .Visible = True
End With
End Sub
I created a custom menubar in the "Menu bar" and saved it in a global
template.
Sometimes it just does not appear on my Mac and sometimes it does not appear
on our users'Mac.
What could cause this unpredictable behaviour of the menu?
gr. Marco
--
Please reply to the newsgroup to maintain the thread. Please do not email
me unless I ask you to.
John McGhie <
[email protected]>
Microsoft MVP, Word and Word for Macintosh. Consultant Technical Writer
Sydney, Australia +61 4 1209 1410