ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   routine won't recurse (https://www.excelbanter.com/excel-programming/352144-routine-wont-recurse.html)

Eric[_27_]

routine won't recurse
 
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



Bob Phillips[_6_]

routine won't recurse
 
You cannot declare the argument as type commandbar if you are going to pass
commandbars, popups and buttons through it. Try declaring it as a generic
object.

--
HTH

Bob Phillips

(remove nothere from email address if mailing direct)

"Eric" wrote in message
ink.net...
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






All times are GMT +1. The time now is 05:04 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com