commandbars in add-in

G

Geoff

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("Custom Tools")
popupbar.Controls(1).Enabled = True
popupbar.Controls(2).Enabled = True
End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top