Unprotect and protect all sheets in all open/active workbooks

Wikell

New Member
Joined
Jun 2, 2011
Messages
9
Hi, I would like a VBA-code that for all sheets in all currently open workbooks in Excel unlocks all sheets (all sheets have the same password "123456") in all workbooks (it is the tabs that are locked, not the workbooks). I don't want to enter the VBA-code in all files, ie I want to be able to call the VBA-code once for all open workbooks and all sheets in Excel. I need the same VBA code that does exactly the same thing but the opposite, ie locks all tabs for all open workbooks (all tabs have the same password "123456"). The VBA-code I have already found is not working for all open workbooks and all sheets, I need to call the VBA-code in each workbook.
 

Excel Facts

Excel motto
Not everything I do at work revolves around Excel. Only the fun parts.
Is this what you are looking for
VBA Code:
Sub Unprotect_sheets_all_active_workbooks()
Dim wb As Workbook
Dim sht As Worksheet
On Error GoTo errhnd
unpass = 123456
'or use input box for password  unpass = InputBox("password")
For Each wb In Application.Workbooks
'Ignore Personal workbook if there is one
  If wb.Name <> "PERSONAL.xlsb" Then
    For Each sht In wb.Worksheets
    ' Change below LINE to sht.Protect Password:=unpass TO protect all sheets
        sht.Unprotect Password:=unpass
    Next sht
  End If
Next wb
Exit Sub
errhnd: MsgBox "There is s problem - check your password, capslock, etc."

End Sub
 
Upvote 0
Is this what you are looking for
VBA Code:
Sub Unprotect_sheets_all_active_workbooks()
Dim wb As Workbook
Dim sht As Worksheet
On Error GoTo errhnd
unpass = 123456
'or use input box for password  unpass = InputBox("password")
For Each wb In Application.Workbooks
'Ignore Personal workbook if there is one
  If wb.Name <> "PERSONAL.xlsb" Then
    For Each sht In wb.Worksheets
    ' Change below LINE to sht.Protect Password:=unpass TO protect all sheets
        sht.Unprotect Password:=unpass
    Next sht
  End If
Next wb
Exit Sub
errhnd: MsgBox "There is s problem - check your password, capslock, etc."

End Sub
Yes, it seams to be exactly what I'm looking for, many thanks! The only thing which seams to not work is to set a password and then use MessageBox for both protect and unprotect sheets.
 
Upvote 0

Forum statistics

Threads
1,215,054
Messages
6,122,893
Members
449,097
Latest member
dbomb1414

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top