Need help for closing the active worksheet only under conditions

  • Thread starter Thread starter Frank Petschke
  • Start date Start date
F

Frank Petschke

Hallo,
i am looking for a VBA-Sub (or hints) to close the active worksheet
(containes my vba-project) as the least worksheet.

If the active worksheet is not the only opened worksheet, "close" should not
work or better should not shown within the system menu of the worksheet
window ...

Please help me, it is very urgend for me to solve this problem!
 
Hi Frank
not totally foolproof but give it a try: Put the following in your
workbook module:

Private Sub Workbook_BeforeClose(Cancel As Boolean)
if Application.Workbooks.Count > 1 then
MsgBox "There are still " & Application.Workbooks.Count & "
open. Closing is cancelled"
Cancel = True
end if
End Sub
 
Back
Top