Unexpected hide of toolbars

S

Stephan

On open time in the autoOpen Macro I create some toolbars. The toolbars are
visibel until the end of the autoOpen Macro but then the toolbars where hide
by some one.
If I debug the autoOpen macro the toolbars don't hide. So in the real
application word maks somthing after the call of autoOpen.

What should I do to keep the toolbars visible.
 
J

Jean-Guy Marcil

Stephan was telling us:
Stephan nous racontait que :
On open time in the autoOpen Macro I create some toolbars. The
toolbars are visibel until the end of the autoOpen Macro but then the
toolbars where hide by some one.
If I debug the autoOpen macro the toolbars don't hide. So in the real
application word maks somthing after the call of autoOpen.

What should I do to keep the toolbars visible.

Word does not hide toolbar for no reasons. Since you are programmatically
creating the toolbar when the document opens, there is something in you code
that is not right.

Make sure you specify that the toolbar must be visible in the code and also,
it might help, check the CustomizationContext property.

If none of this help, then post back with your code. If your code is not too
long and easy to read, maybe someone will have the time to debug it for you,
unless something obvious is missing... then you will get a quick reply.
--
Salut!
_______________________________________
Jean-Guy Marcil - Word MVP
(e-mail address removed)
Word MVP site: http://www.word.mvps.org
 
S

Stephan

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
 
S

Stephan

The rowIndex doesn't solve the problem. I also tried to set the
toolbar.Context to the active document with no success.
If I remove the CustomizationContext = Documents(ActiveDocument) it will be
opened but it is attached to word and not to the document. But the toolbar
should be atteched to the activedocument.

I still hope for help

Stephan
 
J

Jean-Guy Marcil

Stephan was telling us:
Stephan nous racontait que :
The rowIndex doesn't solve the problem. I also tried to set the
toolbar.Context to the active document with no success.
If I remove the CustomizationContext = Documents(ActiveDocument) it
will be opened but it is attached to word and not to the document.
But the toolbar should be atteched to the activedocument.

The few times I played around with toolbars attached to documents, I found
the whole thing quite dodgy and unreliable. So I never really use them like
that. Hopefully someone with more experience in this particular area will be
along shortly!

Why must the toolbar be attached to the document?

--
Salut!
_______________________________________
Jean-Guy Marcil - Word MVP
(e-mail address removed)
Word MVP site: http://www.word.mvps.org
 
S

Stephan

Becaause in the toolbar are real lsit boxes with contents loded for the
specific document. In the example I removed them. Because it is not relevant
for the problem.
 

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