Before Close Event Hide all Worksheets then Close Application

R

RyanH

I have a workbook with some sensitive info on certain worksheets. So I
created a BeforeClose_Event that hides all the worksheets when the workbook
is closed. I then created a Login UserForm with usernames and passwords so
when certain users sign in the code will unhide the worksheets that pretain
to that user. The problem is when I click the Red "X" in the top right hand
corner it only hides the worksheets and the workbook remains open, why?

I want all default features of Excel to remain the same, when the Red X is
clicked it gives you the option to save and then the application closes. How
do I do that?

Private Sub Workbook_BeforeClose(Cancel As Boolean)

Windows(ThisWorkbook.Name).Visible = False

End Sub

Private Sub Workbook_Open()

frmLogin.Show

End Sub


Thanks in Advance,
Ryan
 

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