Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Displaying Custom Toolbar with VBA

Status
Not open for further replies.

baltco

Instructor
Sep 10, 2003
5
US
I am having difficulty displaying a custom toolbar I created in a template. The toolbar is showing when I save the template, but when a new doc is created from that template the toolbar disappears. I don't want my users to have to open the toolbar on their own.

I attempted to force the toolbar open with the below procedure, which is called when the new document is created, (see beyone this procedure for the code contained in the template's Document_New() procedure). Thanks for any help anyone can provide. John


Public Sub handoutBar()

'This procedure displays the handout toolbar

toggleProtectOff
CommandBars("Handout").Visible = True
toggleProtectOn


End Sub


Private Sub Document_New()

If ActiveDocument.ProtectionType <> wdNoProtection Then
toggleProtectOff

End If

' open Course Information Form

frmCourseInformation.Show

' The following procedure is used to update fields in the footers

updateFields

' The following procedure displays the handout bar

handoutBar

End Sub
 
Hi,

Since displayed Toolbar are configured by the user, your procedure should

If tool bar does not exist then
create the toolbar

If toolbar is not displayed then
display toolbar

When the Object that you have placed the toolbar in closes, delete or set the visible property false for the toolbar

:)

Skip,
Skip@TheOfficeExperts.com
 
Thanks for your reply, Skip. I am a relative new comer to VBA, so please excuse my ignorance. Are you saying that if I have created the toolbar in the template, that I must recreate it using VBA at the time the doc is opened? I was really just looking for a way to have it display when they begin working with the document.

If it must be created with VBA, can you point me to some tutorials on doing that. I really appreciate it, finding VBA help, books and the like for Word is murderous. While there are materials for Excel, everyone seems to have ignored the Word Object Model. Thanks again for your help. John
 
Well, I guess taht I am saying that since it is already there, your code would simply have to display it.
Code:
Private Sub Document_Open()
    Application.CommandBars(&quot;MyToolBarName&quot;).Visible = True
End Sub
Paste this in the Document Object in the VB Editor.

:)

Skip,
Skip@TheOfficeExperts.com
 
You might also want to specify the Position of this toolbar. the possibilities are
Code:
msoBarLeft, msoBarTop, msoBarRight, msoBarBottom, msoBarFloating, msoBarPopup, or msoBarMenuBar
Code:
Private Sub Document_Open()
    With Application.CommandBars(&quot;Control Toolbox&quot;)
        .Visible = True
        .Position = msoBarFloating
    End With
End Sub
:)

Skip,
Skip@TheOfficeExperts.com
 
I tried this Skip and it still doesn't display the toolbar, its there, but I have to select it from the toolbar list to display it.

I am a little puzzled though in how the Document_Open() procedure will help since I am creating a new doc from the template. Will a document open event also be triggered at the time it is created. I had already tried putting essentially the same code in the Document_New() event procedure, without any success. John
 
Skip, the toolbar name is handout. John
 
I believe I have isolated the problem with the display of this toolbar. The code seems to work fine when displaying a built-in toolbar (database, forms, etc.) but doesn't work with any of the toolbars I create for the template.

I created another template and toolbar for that template and was able to recreate that behavior. Does anyone know if the syntax is different when referencing a user toolbar, or perhaps can point out some context problem I may be experiencing? Thanks for your help, John
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top