Disable custom drop-down menu

P

Piers 2k

Hi folks,

Have a file on a public drive which is opened by a number of users using Alt
Startup Location configured in options. Workbook is hidden, and Open and
BeforeClose events work correctly to create and drop a custom menu. All
fine.

Except when no workbooks are open, the menu isn't disabled in any way. Is
there a way to disable the entire menu or certain items when no other files
are open?

TIA,

Piers
 
B

Bob Phillips

See if this works for you

Option Explicit

Public WithEvents App As Application

Private Sub App_WindowActivate(ByVal Wb As Workbook, ByVal Wn As Window)
Dim win As Window
Dim cnt As Long
For Each win In Application.Windows
cnt = cnt - win.Visible
Next win
If cnt > 1 Then Application.Commandbars("myMenu").Enabled=True
End Sub

Private Sub App_WindowDeactivate(ByVal Wb As Workbook, ByVal Wn As Window)
Dim win As Window
Dim cnt As Long
For Each win In Application.Windows
cnt = cnt - win.Visible
Next win
If cnt = 1 Then Application.Commandbars("myMenu").Enabled=False
End Sub

Private Sub Workbook_Open()
Set App = Application
End Sub

'This is workbook event code.
'To input this code, right click on the Excel icon on the worksheet
'(or next to the File menu if you maximise your workbooks),
'select View Code from the menu, and paste the code



--
HTH

Bob Phillips

(replace somewhere in email address with gmail if mailing direct)
 

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