Password protect a sheet

jamienwood

Board Regular
Joined
Apr 14, 2002
Messages
133
I have a system to be used by many and there is one sheet where i only want people that know a password to be able to see it, is there a way that when someone clicks the sheet tab or a linking password that they are asked for a password???
 

Excel Facts

Copy PDF to Excel
Select data in PDF. Paste to Microsoft Word. Copy from Word and paste to Excel.
On 2002-04-29 02:08, jamienwood wrote:
I have a system to be used by many and there is one sheet where i only want people that know a password to be able to see it, is there a way that when someone clicks the sheet tab or a linking password that they are asked for a password???

Place code in the Thisworkbook object;
Notes
1) Change sPwd const to your password
2) Change the Sh.Name = "Sheet3" to your
sheet name that you want password protected.

<pre/>
'// Change to your password
Const sPwd As String = "mypassword"
Dim LastSheet

Private Sub Workbook_SheetActivate(ByVal Sh As Object)
Dim OK As String
If Sh.Name = "Sheet3" Then
OK = InputBox("Please enter password", "Sheet Sentry")
If OK <> sPwd Then Sheets(LastSheet).Activate
End If
End Sub

Private Sub Workbook_SheetDeactivate(ByVal Sh As Object)
LastSheet = Sh.Name
End Sub
</pre>
 
Upvote 0
What syntax would I use to employ the PasswordChar function on this example?

TIA

Cheers - Paul
 
Upvote 0
i have but this code into VBA but it doesnt seem to do anything, maybe it me but does anyone know how to make it work??
 
Upvote 0
put the code in the worksheet that you want the user asked for the password not in a module.
 
Upvote 0
i have tried putting this code onto the sheet code but it still doesnt do anything is it meant to ask for the password when i click on the page or is anymore code needed??
 
Upvote 0
On 2002-04-30 01:06, jamienwood wrote:
i have tried putting this code onto the sheet code but it still doesnt do anything is it meant to ask for the password when i click on the page or is anymore code needed??

Put the code into the Thisworkbook object
and Not the sheets code module as I specified
See if this works.
Also note the other Notes i made
Good luck
 
Upvote 0
i have got the message box to pop up, but even though i have changed the password like you said when you enter the password and click ok you are taken back to your last sheet and if you press cancel it lets you in???

just to check this is what i changed the code to:
'// Change to your password
Const user12 As String = "mypassword"
Dim LastSheet

Private Sub Workbook_SheetActivate(ByVal Sh As Object)
Dim OK As String
If Sh.Name = "Passworded" Then
OK = InputBox("Please enter password", "Sheet Sentry")
If OK <> user12 Then Sheets(LastSheet).Activate
End If
End Sub

Private Sub Workbook_SheetDeactivate(ByVal Sh As Object)
LastSheet = Sh.Name
End Sub
 
Upvote 0

Forum statistics

Threads
1,213,538
Messages
6,114,218
Members
448,554
Latest member
Gleisner2

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