Disable custom drop-down menu

  • Thread starter Thread starter Piers 2k
  • Start date Start date
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
 
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)
 
Back
Top