2022-05-13

How do I get the source worksheet to become password protected after a copy is made by clicking an active x button?

The code below is activated from an active x button. The code will unprotect the active workbook and worksheet, make a copy of the active worksheet, place that new sheet's tab where I want it to be placed, protect the new worksheet, and protect the workbook. It fails to protect the Source Worksheet that the copy was made from. I need the code to password protect the Last Active Sheet too (the Source Sheet the Copy was made from). Any help is greatly appreciated.

Private Sub CommandButton13_Click()
ThisWorkbook.Unprotect Password:="Password1"
ActiveSheet.Unprotect Password:="Password2"
Dim i As Long, s As String, s2 As String
s = "NEW WONDERFUL WORKSHEET"
s2 = s
ActiveSheet.Copy After:=Sheets(2)
Do While WorksheetExists(s2)
    i = i + 1
    s2 = s & " " & i
Loop
ActiveSheet.Name = s2
ActiveSheet.Protect Password:="Password2"
ThisWorkbook.Protect Password:="Password1"
End Sub


No comments:

Post a Comment