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
 

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

Back
Top