ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   New Users to Excel (https://www.excelbanter.com/new-users-excel/)
-   -   Code to protect all the worksheets in a book (https://www.excelbanter.com/new-users-excel/265339-code-protect-all-worksheets-book.html)

bill_ball

Code to protect all the worksheets in a book
 
Hi Experts,

I need a code to protect all the sheets in a workbook dynamically. i may add sheets or delete sheets but protection of the sheets should be dynamic.

thanks in advance.

bala_vb

Quote:

Originally Posted by bill_ball (Post 958696)
Hi Experts,

I need a code to protect all the sheets in a workbook dynamically. i may add sheets or delete sheets but protection of the sheets should be dynamic.

thanks in advance.

try this vba code in the VBE editor.

Sub ProtectAllSheets()
'Protects ALL worksheets
For Each Shts In ThisWorkbook.Worksheets
Shts.Protect Password:=secret
Next
End Sub.

if you are using excel 2007 version, copy this code to .xlsm (macro enabled) or excel 2003 you can directly copy to .xls spread sheet.

all the best


All times are GMT +1. The time now is 06:00 PM.

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