I have reduce the code to the minimum. With this code I have the same
problem. If I open this document the toolbars hide.
NOTE: The macro is defined in a Templat and not in the document itself.
sinceraly
Stephan
Code -----------------------------------------
Option Explicit
'----------------------------------------------------------------------------------'
Private Sub Ftest()
'----------------------------------------------------------------------------------'
'----------------------------------------------------------------------------------'
MsgBox "Ftest"
End Sub
'----------------------------------------------------------------------------------'
Private Sub makeToolBarEntry(Bar As CommandBar, ID As Long, entryType,
faceId As Long, tag As String, cap As String, group As Boolean, action As
String, Optional width As Long = 0, Optional visible As Boolean = True,
Optional enable As Boolean = True)
'----------------------------------------------------------------------------------'
' Description: This Procedure adds a control to the given tool bar.
' if a control with the same id exists this control will be
deleted.
' Input: Bar the command bar to add the control
' ID the id of the control
' entryType the type of the control ()
' faceId the id of the icon
' tag the tag text
' cap the caption text
' group insert a group delimiter
' action the function name of the function to be called
on selection
' width the size (distance) of the control
' visible is the control visible
' enable is the control enabel
' Return: None
'----------------------------------------------------------------------------------'
Dim c As Control
On Error Resume Next
c = 0
c = Bar.Controls(ID)
If c <> 0 Then
Bar.Controls(ID).Delete
End If
Bar.Controls.Add Type:=entryType
Bar.Controls(ID).faceId = faceId
Bar.Controls(ID).tag = tag
Bar.Controls(ID).Caption = cap
Bar.Controls(ID).BeginGroup = group
Bar.Controls(ID).OnAction = action
Bar.Controls(ID).Enabled = enable
If width > 0 Then
Bar.Controls(ID).width = width
End If
Bar.Controls(ID).visible = visible
End Sub
'----------------------------------------------------------------------------------'
Private Sub createTestBar()
'----------------------------------------------------------------------------------'
' Description: This Procedure creates a test toolbar. Before the toolbar is
created
' if a toolbar with the same name exists this toolbar will be
deleted.
' Input: None
' Return: None
'----------------------------------------------------------------------------------'
Dim toolBar As CommandBar
CustomizationContext = Documents(ActiveDocument)
On Error Resume Next
' remove old toolbar
Set toolBar = Nothing
Set toolBar = Word.ActiveDocument.CommandBars("Test Bar")
If Not toolBar Is Nothing Then
toolBar.Delete
End If
Set toolBar = Nothing
Set toolBar = Word.CommandBars("Test Bar")
If Not toolBar Is Nothing Then
toolBar.Delete
End If
Set toolBar = Word.ActiveDocument.CommandBars.Add("Test Bar")
toolBar.visible = True
makeToolBarEntry toolBar, 1, msoControlButton, 233, "", "", True,
"Ftest", 35
makeToolBarEntry toolBar, 2, msoControlButton, 215, "", "", False,
"Ftest", 35
makeToolBarEntry toolBar, 3, msoControlButton, 454, "", "", False,
"Ftest", 35
makeToolBarEntry toolBar, 4, msoControlButton, 366, "", "", False,
"Ftest", 35
makeToolBarEntry toolBar, 5, msoControlButton, 357, "", "", False,
"Ftest", 35
makeToolBarEntry toolBar, 6, msoControlButton, 49, "", "", True,
"Ftest", 35
End Sub
'----------------------------------------------------------------------------------'
Public Sub createBars()
'----------------------------------------------------------------------------------'
' Description: This Procedure creates all needed tool bars.
' Input: None
' Return: None
'----------------------------------------------------------------------------------'
createTestBar
' ... and more toolbars
' ...
End Sub
'----------------------------------------------------------------------------------'
Public Sub autoOpen()
'----------------------------------------------------------------------------------'
'----------------------------------------------------------------------------------'
createBars
End Sub