Questions, criticisms and comments welcome - there must be an easier way!
'---------------------------------------------------------------------------------------
' Procedure : hasAtLeastOneControlEnabled
' Purpose : Determines if the passed command bar has at least one control
enabled. If the
' bar has even one control enabled then the bar should be
enabled; if no
' controls enabled then the bar needs to be disabled.
' Inputs : CommandBar the command bar of interest
' Outputs : Boolean True if one control is enabled (the first one
found is enough).
' Precon(s) : The controls have already been enabled/disabled based on
context.
' DateTime : 2/1/2006
' Author : EBF
'---------------------------------------------------------------------------------------
'
Private Function hasAtLeastOneControlEnabled(aParentBar As
Office.CommandBar) As Boolean
On Error Resume Next
Dim bResult As Boolean
Dim ctl As Office.CommandBarControl
For Each ctl In aParentBar.Controls
If TypeOf ctl Is CommandBarPopup Then
bResult = hasAtLeastOneControlEnabled(ctl) <====this doesn't
recurse here
Else
If ctl.Enabled Then
bResult = True
hasAtLeastOneControlEnabled = bResult
Exit Function
End If
End If
Next ctl
End Function
Bookmarks