Tonight I want to automatically protect and unprotect all Microsoft Excel Worksheets in my Workbook with password, instead of doing it manually, I put these following Excel VBA macro code in my Workbook.
Public Sub ProtectAllSheets() Dim objSheet As <a title="See also Create New Excel Worksheet With VBA"href="http://excelvbamacro.com/create-new-excel-worksheet-with-vba.html">Worksheet</a> 'Protecting all worksheets with password For Each objSheet In Worksheets If objSheet.ProtectContents = False Then objSheet.Protect"a@#&ladfl&^" Next objSheet End Sub Public Sub UnProtectAllSheets() Dim objSheet As Worksheet 'UnProtecting all worksheets with password For Each objSheet In Worksheets If objSheet.ProtectContents = True Then objSheet.Unprotect"a@#&ladfl&^" Next objSheet End Sub
We only need to call the procedure ProtectAllSheets to protect with password all Excel Worksheets in our Workbook, and calling UnProtectAllSheets will reversed the effect.
SOURCE | LINK | LANGUAGE | ENGLISH |