View Single Post
  #1   Report Post  
Posted to microsoft.public.excel.programming
Geoff Geoff is offline
external usenet poster
 
Posts: 371
Default commandbars in add-in

Hi
I have created an add-in and want to disable (not remove) my custom menu
when all wbooks are closed and only the add-in is left open. The menus are
removedwhen the add-in is closed.

The following code seemed to work ok at first then errored with 'Invalid
Procedure call' I would appreciate any advice as to where I am going wrong.

T.I.A.

Geoff

I have put this code in a class CAppEvents

Dim WithEvents oApp As Application
Private Sub Class_Initialize()
Set oApp = Application
End Sub

Private Sub oApp_WorkbookDeactivate(ByVal Wb As Workbook)
If Not Workbooks.Count 1 Then
Set popupbar = Application.CommandBars.ActiveMenuBar.Controls
_("CustomTools") ''''''Fails here
popupbar.Controls(1).Enabled = False
popupbar.Controls(2).Enabled = False
End If
End Sub

Private Sub oApp_WorkbookActivate(ByVal Wb As Workbook)
Set popupbar = Application.CommandBars.ActiveMenuBar.Controls("Cu stom Tools")
popupbar.Controls(1).Enabled = True
popupbar.Controls(2).Enabled = True
End Sub