ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Sheet protection (https://www.excelbanter.com/excel-programming/366053-sheet-protection.html)

Marcelo Rychter[_6_]

Sheet protection
 

Hi folks,

I used the code below to protect a sheet:

ActiveSheet.EnableSelection = xlNoSelection
ActiveSheet.Protect Password:="CADEMP"

It works properly. I tested it after running the code.

But when I save the worksheet and reopen it I CAN select the cells. It
seems that the code was not effective.

But when I do the same procedure using the Excel menu
(Tolls/Protect/...) and save, when a reopen the woksheet it works
properly.

Do some of you know how to avoid the problem?

Thanks,
Marcelo Rychter


--
Marcelo Rychter
------------------------------------------------------------------------
Marcelo Rychter's Profile: http://www.excelforum.com/member.php...o&userid=35066
View this thread: http://www.excelforum.com/showthread...hreadid=557625


Norman Jones

Sheet protection
 
Hi Marcelo,

The EnableSelection property is not persistent.

Try, therefo

'=============
Private Sub Workbook_Open()
Dim SH As Worksheet

Set SH = Me.Worksheets("Sheet1") '<<==== CHANGE

With SH
.EnableSelection = xlNoSelection
.Protect Password:="CADEMP"
End With

End Sub
'<<=============

This is workbook event code and should be pasted into the workbook's
ThisWorkbook module *not* a standard module or a sheet module:

Right-click the Excel icon on the worksheet
(or the icon to the left of the File menu if your workbook is maximised)

Select 'View Code' from the menu and paste the code.


---
Regards,
Norman


"Marcelo Rychter"
wrote in
message news:Marcelo.Rychter.2aan6z_1151802903.15@excelfor um-nospam.com...

Hi folks,

I used the code below to protect a sheet:

ActiveSheet.EnableSelection = xlNoSelection
ActiveSheet.Protect Password:="CADEMP"

It works properly. I tested it after running the code.

But when I save the worksheet and reopen it I CAN select the cells. It
seems that the code was not effective.

But when I do the same procedure using the Excel menu
(Tolls/Protect/...) and save, when a reopen the woksheet it works
properly.

Do some of you know how to avoid the problem?

Thanks,
Marcelo Rychter


--
Marcelo Rychter
------------------------------------------------------------------------
Marcelo Rychter's Profile:
http://www.excelforum.com/member.php...o&userid=35066
View this thread: http://www.excelforum.com/showthread...hreadid=557625





All times are GMT +1. The time now is 12:26 PM.

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