ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Sheet Protection & Password (https://www.excelbanter.com/excel-programming/414700-sheet-protection-password.html)

will07

Sheet Protection & Password
 
Hello Everybody,

Is it possible to add some code to each worksheet that will enable me to
protect the worksheet and have a permanent password. At the moment, when you
unprotect the worksheet, you have to re-enter the password (twice) to protect
it again. I would like to be able to have the password in place all the time
so the user does not have to re-enter it again and again.

Thanks heaps

Corey ....[_2_]

Sheet Protection & Password
 
Something like:
Sub Unprotect()
ThisWorkbook.Worksheets("Report").Unprotect Password:="Password HERE"
ActiveSheet.Unprotect
End Sub

Sub Protect()
ThisWorkbook.Worksheets("Report").Protect Password:="Password HERE"
ActiveSheet.Protect
End Sub

You could add the codes to the WorkSheet_Change vent or similar to suit.


Corey...


"will07" wrote in message
...
Hello Everybody,

Is it possible to add some code to each worksheet that will enable me to
protect the worksheet and have a permanent password. At the moment, when
you
unprotect the worksheet, you have to re-enter the password (twice) to
protect
it again. I would like to be able to have the password in place all the
time
so the user does not have to re-enter it again and again.

Thanks heaps




RyanH

Sheet Protection & Password
 
I would use this code. This will protect or unprotect all your sheets. You
can call this code several ways.

1.) Setup a custom buttons in a toolbar and assign a macro to each one.
This way you just click a button in the toolbar and "Waaala" the worksheets
are protected.

2.) You can put the code in a Worksheet Event such as: Worksheet_Activate
and Worksheet_Deactivate. This will unprotect the worksheet when it is
selected and protect it when another sheet is selected.

3.) Put command buttons on the worksheet somewhere and assign these macros
to them.

I use #1.

Sub Protect()

Dim wks As Worksheet

For Each wks In Worksheets
wks.Protect Password:="password"
Next wks

End Sub

Sub UnProtect()

Dim wks As Worksheet

For Each wks In Worksheets
wks.UnProtect Password:="password"
Next wks

End Sub

--
Cheers,
Ryan


"will07" wrote:

Hello Everybody,

Is it possible to add some code to each worksheet that will enable me to
protect the worksheet and have a permanent password. At the moment, when you
unprotect the worksheet, you have to re-enter the password (twice) to protect
it again. I would like to be able to have the password in place all the time
so the user does not have to re-enter it again and again.

Thanks heaps



All times are GMT +1. The time now is 09:35 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com