Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I protect all worksheet in an Excel workbook with a single click?

Tags:

excel

vba

I have around 25 worksheets in my workbook (Excel spreadsheet). Is there a way I can protect all the 25 worksheets in single click ? or this feature is not available and I will have to write a VBA code to accomplish this. I need very often to protect all sheets and unprotect all sheets and doing individually is time consuming

like image 904
Dheer Avatar asked Oct 10 '08 13:10

Dheer


1 Answers

I don't believe there's a way to do it without using VBA. If you are interested in a VBA solution, here is the code:

Dim ws as Worksheet
Dim pwd as String

pwd = "" ' Put your password here
For Each ws In Worksheets
    ws.Protect Password:=pwd
Next ws

Unprotecting is virtually the same:

Dim ws as Worksheet
Dim pwd as String

pwd = "" ' Put your password here
For Each ws In Worksheets
    ws.Unprotect Password:=pwd
Next ws
like image 190
Ben Hoffstein Avatar answered Sep 27 '22 23:09

Ben Hoffstein