Question : Password protect Macro Code

The code below password protects all tabs (worksheets) in my workbook upon closing.  How would I go about modifying this code to exclude certain worksheets from being protected when this Macro runs?  I still want most of them to protect upon closing the workbook, but there are 3 that I'd like to remain unprotected.

Regards,
WD
Code Snippet:
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
Private Sub Workbook_Open()
 
 Dim LinkSource As Variant
   Dim Result As Long
   Dim FocusSheet As Worksheet
   
   Const Password = "Rainbow"
 
   If Not IsDate(Sheets("Closing").[B4]) Then
      'Result = MsgBox("Do you want to update external links?", vbYesNo + vbQuestion)
      'If Result = vbYes Then
         For Each FocusSheet In Sheets
            FocusSheet.Unprotect Password
         Next FocusSheet
         For Each LinkSource In ThisWorkbook.LinkSources
            ThisWorkbook.UpdateLink Name:=LinkSource, Type:=xlExcelLinks
         Next LinkSource
         For Each FocusSheet In Sheets
            FocusSheet.Protect Password:=Password, AllowFormattingColumns:=True, AllowFormattingRows:=True
         Next FocusSheet
      'End If
   End If
    
  Application.OnKey "{TAB}"
  Application.OnKey "+{TAB}"
  
End Sub
Open in New Window Select All

Answer : Password protect Macro Code

You sure it protects the workbook while closing because the code that you have is on the open command not on closing...so if you need to make it on closing thats the first change that you need to make....

Second to ignore the sheets that you dont want to protect then use this...as in edit your existing lines in your macro which is lines 18 to 20..that is these lines...

For Each FocusSheet In Sheets
            FocusSheet.Protect Password:=Password, AllowFormattingColumns:=True, AllowFormattingRows:=True
         Next FocusSheet

to this...

For Each FocusSheet In Sheets
if(FocusSheet.name<>"Your first worksheet name that you dont want to protect" and FocusSheet.name<>"Your second worksheet name that you dont want to protect" and FocusSheet.name<>"Your third worksheet name that you dont want to protect") then
 FocusSheet.Protect Password:=Password, AllowFormattingColumns:=True, AllowFormattingRows:=True
end if
         Next FocusSheet
Random Solutions  
 
programming4us programming4us