View Single Post
  #7   Report Post  
Posted to microsoft.public.excel.programming
Tom Ogilvy Tom Ogilvy is offline
external usenet poster
 
Posts: 27,285
Default Enable/Disable CommandBar Buttons Based on Events

with xlApp.CommandBars(1).Controls("PIMS TIPS")
for i = 1 to .count
controls(i).Enabled = False
Next i
End with


or
xlApp.CommandBars(1).Controls("PIMS TIPS").Controls("MyFirstItem").Enabled
= False

for the specific control with a caption of "MyFirstItem" as an example.

--
Regards,
Tom Ogilvy


"M. Authement" wrote in message
...
OK, I got it to work if I want to disable the entire menu. Here is the
code I used in the sheet activate event.

Private Sub xlApp_SheetActivate(ByVal Sh As Object)

Dim bEnableDisable As Boolean

If TypeName(Sh) = "Worksheet" Then
bEnableDisable = True
Else
bEnableDisable = False
End If
Debug.Print TypeName(Sh) & ", " & bEnableDisable
'On Error Resume Next
xlApp.CommandBars(1).Controls("PIMS TIPS").Enabled = bEnableDisable
'On Error GoTo 0

End Sub

I have several controls under the PIMS TIPS menu and would prefer to
disable them at that level but could not figure out how to access them.
What I have above will work, but can you help me understand how to
reference a control's controls?


"Tom Ogilvy" wrote in message
...
Look at application level events

http://www.cpearson.com/excel/appevent.htm

You would have to use the application level workbook close event to
determine when all the visible workbooks are closed.

You would use the sheetactivate and deactivate events to determine if it
is a worksheet or not.

--
Regards,
Tom Ogilvy


"M. Authement" wrote in message
...
I have added a menu item with several sub-menu commands as part of an
add-in I am developing. Many of these commands deal with modifying or
inserting cell formulas, so I would like to disable those commands if no
workbook is open or if the activesheet is not a worksheet. How do I go
about doing this? I am using WinXP, XL2003.