Warning Message on Excel Exit

stevembe

Well-known Member
Joined
Mar 14, 2011
Messages
501
With help through these forums I have managed to set up the following code that hides/unhides a single work sheet in a workbook and is password protected (password deleted):

Sub ToggleCompSheets()
Dim ConfirmHide As String
Application.ScreenUpdating = False
If Sheets("HR Data").Visible = xlSheetVeryHidden Then
GetCompApproval
Sheets("HR Data").Visible = xlSheetVisible
Sheets("HR Data").Activate
Else
ConfirmHide = MsgBox(prompt:="This will hide the HR Data tab." & vbCr & vbCr & _
"You will need a password to access " & vbCr & _
"the tab if you choose to continue." & vbCr & vbCr & _
"Do you wish to continue?", Buttons:=vbYesNo, _
Title:="Hide HR Data Tab")
If ConfirmHide = vbNo Then
End
Else
Sheets("HR Data").Visible = xlSheetVeryHidden
Sheets("Index").Activate
'Range("c8").Select
End If
End If
End Sub


Sub GetCompApproval()
Dim Password As String
Dim RetryPass As String
Password = InputBox(prompt:="Enter password to display HR Data tab", Title:="Password")
'MsgBox prompt:=Password
If Password = "" Then
End
ElseIf Password <> "" Then
RetryPass = MsgBox(prompt:="Sorry, password is incorrect" & vbCr & _
"contact Steve on Ext ****" & vbCr & _
"if you need a password", _
Title:="Access Denied", _
Buttons:=vbRetryCancel + vbExclamation)
If RetryPass = vbRetry Then
GetCompApproval
Else

End
End If
Else
Sheets("HR Data").Visible = xlSheetVisible
Sheets("HR Data").Activate

End If
End Sub

My problem is that if users who have access to the worksheet forget to hide it before closing or exit the sheet will be visible to anybody when opened again. I am after a reminder pop up on exit or closure that states "Please ensure the hidden tab has been hidden" and with three button options as follows:

Worksheet Hidden Continue with Exit (Action closes excel)

Return to Workbook (Returns the user to workbook)

Non Applicable (closes excel, this is for users who do not have access to the spreadsheet)

Can anybody advise, thanks in advance.

Steve
 

Excel Facts

Formula for Yesterday
Name Manager, New Name. Yesterday =TODAY()-1. OK. Then, use =YESTERDAY in any cell. Tomorrow could be =TODAY()+1.

Forum statistics

Threads
1,224,537
Messages
6,179,408
Members
452,912
Latest member
alicemil

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top