Command Bars

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I am trying to create a custom command bar using VBA but then compiler is not
recognizing the CommandBar type. For example when I compile my project the
line:

Dim cbr as CommandBar

gives me an error : "User-defined type not defined".

Do I need to set a reference to a particular library to access the
commandbars collection/objects?

Thanks in advance.
 
Rick

Add the Office library to your references...or do what I do and dim it as
Object in case your users do not have the same version of Office that you
have.

Public Function ViewTbarBtn(idx As Long, bolVisible As Boolean)
'Purpose : Hide or show button on tbrPrintRptSnp toolbar.
' Use eTbarIdx for idx value.
' Used mostly to hide Excel button for reports that do not
' convert nicely to a spreadsheet.
'DateTime : 2/4/2005 14:21
'Author : Bill Mosca
Dim tbr As Object
Dim btn As Object

Set tbr = Application.CommandBars("tbrPrintRptSnp")

Set btn = tbr.Controls(idx)

btn.Visible = bolVisible

Set btn = Nothing
Set tbr = Nothing

End Function
 
The CommandBar object (and all the other menu-related objects) are in the
Microsoft Office n Object Library (where n is 8.0 for Office 97, 9.0 for
Office 2000, 10.0 for Office 2002 and 11.0 for Office 2003).

Are you sure you need to create the command bar programmatically though? Why
not add it once to the application, and then simply toggle its visibility?
 
Back
Top