Protecting Multiple Sheets Within A Workbook

Anonymous
2022-09-05T19:49:44+00:00

First thing to say I really don't know how to use VBA code on excel.

Sub ProtectAllSheets()

Dim sh 

For Each sh In Sheets 

    sh.Protect Password:="password" 

Next sh 

End Sub

I got the above by searching on google, and I used the the code to protect all sheets in the excel and it worked wel.

Now, along with protecting all the worksheets at once I also need to uncheck the boxes "Select locked cells" and "Select unlocked cells" is it possible? Can anyone please help me if possible?

A VERY BIG THANK YOU IN ADVANCE!!!

Microsoft 365 and Office | Excel | For home | Windows

Locked Question. This question was migrated from the Microsoft Support Community. You can vote on whether it's helpful, but you can't add comments or replies or follow the question.

0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. HansV 462.4K Reputation points MVP Volunteer Moderator
    2022-09-05T20:16:54+00:00

    That is the default setting, so you don't really have to specify it, but if you'd still like to do so:

    Sub ProtectAllSheets()
        Dim sh As Worksheet
        For Each sh In Worksheets
            sh.EnableSelection = xlNoRestrictions
            sh.Protect Password:="password"
        Next sh
    End Sub
    
    1 person found this answer helpful.
    0 comments No comments