Password Protect the Unhide Sheet Function

J

jkarl

Excel Protection Question.

I would like to be hide an individual Sheet in a Workbook and the
password protect the Unhide function so that only selected Users ca
re-open the individual Sheet.

There are multiple sheets in the workbook and only one Sheet contain
sensitive data.

Thanks for any responses.

-Ji
 
P

Paul B

You could use something like this, it will ask for a password when you
click on the sheet

Private Sub Worksheet_Activate()
Dim strPassword As String
On Error Resume Next
Me.Protect Password:="123"
Me.Columns.Hidden = True

strPassword = InputBox("Enter password to view this sheet")

If strPassword = "" Then
Me.Previous.Select
Exit Sub
ElseIf strPassword <> "123" Then
MsgBox "Password Incorrect "
Me.Previous.Select
Exit Sub
Else
Me.Unprotect Password:="123"
Me.Columns.Hidden = False
End If

On Error GoTo 0
End Sub

Private Sub Worksheet_Deactivate()
On Error Resume Next
Me.Columns.Hidden = True
On Error GoTo 0
End Sub

To put in this macro right click on the worksheet tab and view code, in the
window that opens paste this code, press Alt and Q to close this window and
go back to your workbook. If you are using excel 2000 or newer you may have
to change the macro security settings to get the macro to run.

You will also need to protect the VBA project so people can't see the
password from there,

To protect the VBA project, from your workbook right-click the workbook's
icon and pick View Code. This icon is to the left of the "File" menu this
will open the VBA editor, in the left hand window right click on your
workbook name and select VBA project properties, protection, check lock
project for viewing and set a password. Press Alt and Q to close this window
and go back to your workbook and save and close the file. Be aware that this
password can be broken by third party software

--
Paul B
Always backup your data before trying something new
Please post any response to the newsgroups so others can benefit from it
Feedback on answers is always appreciated!
Using Excel 97 & 2000
** remove news from my email address to reply by email **
 

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