Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default trying to enable top level command bars by context

I'm using the Parameter property of the controls to enable/disable them along
the lines of a concept from "Prof. Excel Dev.". Since the command bar parent
has no such property, and I want to keep the code reusable, after I've set
all the controls I'm trying the code below, which is documented better then
it works (it doesn't call itself recursively)

Questions, criticisms and comments welcome - there must be an easier way to
do this...

'---------------------------------------------------------------------------------------
' 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

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,253
Default trying to enable top level command bars by context

Eric,

the function parameter s/b passed ByVal and defined as a generic
object, since you're passing it both commandbar and commandbarpopup
objects

i've added a check that the popup itself is enabled and simplified the
code.

Note: For this code to work in xl97 change TypeOf Is to
lcase$(TypeName(octl)) = "commandbarpopup"


Function BarHasEnabledControls(ByVal oParent As Object) As Boolean
Dim oCtl As CommandBarControl
For Each oCtl In oParent.Controls
If TypeOf oCtl Is CommandBarPopup And oCtl.Enabled Then
BarHasEnabledControls = BarHasEnabledControls(oCtl)
Else
BarHasEnabledControls = oCtl.Enabled
End If
If BarHasEnabledControls Then Exit Function
Next
End Function


--
keepITcool
| www.XLsupport.com | keepITcool chello nl | amsterdam


Eric Fingerhut wrote :

I'm using the Parameter property of the controls to enable/disable
them along the lines of a concept from "Prof. Excel Dev.". Since the
command bar parent has no such property, and I want to keep the code
reusable, after I've set all the controls I'm trying the code below,
which is documented better then it works (it doesn't call itself
recursively)

Questions, criticisms and comments welcome - there must be an easier
way to do this...

'---------------------------------------------------------------------
------------------ ' 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

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Command Bars KneeDown2Up Excel Discussion (Misc queries) 4 January 16th 07 05:43 PM
context for the command bar Eric[_27_] Excel Programming 1 February 2nd 06 12:40 PM
Command Bars Neil Hopkinson[_2_] Excel Programming 3 August 19th 05 09:53 AM
Enable a new dimention: sub-level of split cells yarp Excel Discussion (Misc queries) 3 August 8th 05 04:11 PM
command bars Geo Siggy[_16_] Excel Programming 6 April 22nd 04 10:50 AM


All times are GMT +1. The time now is 10:01 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"