Article ID: 202308
Article Last Modified on 10/11/2006
Public Function AllowMenus(CmdBarName As String, CmdbarEnabled As _
Boolean)
'============================================================='
'This function has two arguments: CmdbarName is a string that '
'passes the name of the command bar that the code enables or '
'disables. CmdBarEnabled is a Boolean value in which you pass '
'"True" or "False" in order to enable or disable the command '
'bar being modified. '
' '
'Example: To disable the command bar "NorthwindCustomMenuBar" '
'in the Northwind sample database, use the following: '
' '
'AllowMenus("NorthwindCustomMenuBar",False) '
'============================================================='
Dim Cmdbar As CommandBar, Cbct As CommandBarControl
On Error GoTo Err_AllowMenus
Set Cmdbar = CommandBars(CmdBarName)
If Cmdbar.Visible = False Then Cmdbar.Visible = True
For Each Cbct In Cmdbar.Controls
Cbct.Enabled = CmdbarEnabled
Next Cbct
Exit_AllowMenus:
Exit Function
Err_AllowMenus:
MsgBox "Error " & CStr(Err) & " " & Err.Description & _
" has occurred in the AllowMenus Function", vbOKOnly, _
"Error Detected"
Resume Exit_AllowMenus
End Function
?AllowMenus("NorthwindCustomMenuBar", False)
Public Function CommandbarEnable(Cmdbar As CommandBar, _
CmdbarEnabled As Boolean, TopLevel As Integer, _
Optional Sublevel As Integer)
'================================================================='
'This function has four arguments: '
' '
'Cmdbar is a CommmandBar object that represents the command '
'bar containing the menu item to be enabled or disabled. '
' '
'CmdBarEnabled is a Boolean value in which you pass "True" '
'or "False" in order to enable or disable the menu item being '
'manipulated. '
' '
'TopLevel is an integer representing the index of the Top-level '
'menu item being manipulated. '
' '
'Sublevel is an optional integer representing the index of the '
'menu item being manipulated under the Top-level menu item. '
' '
'Example: To disable only the "File" menu item on the '
'"NorthwindCustomMenuBar" command bar, use the following: '
' '
'CommandbarEnable(Commandbars("NorthwindCustomMenuBar"),False,1) '
' '
'Example2: To disable the "Get External Data" Menu item under '
'the "File" menu item on the "NorthwindCustomMenuBar" command '
'bar, use the following: '
' '
'CommandbarEnable(Commandbars("NorthwindCustomMenuBar"),False,1,3)'
' '
'To "re-enable" the same menu item, use the following: '
' '
'CommandbarEnable(Commandbars("NorthwindCustomMenuBar"),True,1,3) '
'================================================================='
Dim SubCommandbar
On Error GoTo Err_CommandBarEnable
'If the command bar is not visible, make it so.
If Cmdbar.Visible = False Then Cmdbar.Visible = True
'If no menu item on a submenu is selected for enabling\disabling,
'enable\disable the top level menu choice only.
If IsMissing(Sublevel) Or Sublevel = 0 Then
Cmdbar.Controls(TopLevel).Enabled = CmdbarEnabled
'If a menu item on a submenu is selected for
'enabling\disabling, do so now.
Else
Set SubCommandbar = Cmdbar.Controls(TopLevel)
SubCommandbar.Controls(Sublevel).Enabled = CmdbarEnabled
End If
Exit_CommandBarEnable:
Exit Function
Err_CommandBarEnable:
MsgBox "Error " & CStr(Err) & " " & Err.Description & _
" has occurred in the CommandBarEnable Function", vbOKOnly, _
"Error Detected"
Resume Exit_CommandBarEnable
End Function
?CommandbarEnable(Commandbars("NorthwindCustomMenuBar"),False,1,3)
Additional query words: enabling disabling inf toolbar toolbars commandbar
Keywords: kbdta kbhowto kbofficeprog kbprogramming KB202308