0
votes

I've been trying to protect a worksheets in excel using VBA that would ask the user to input password each time he try to edit it or unprotect the sheet. I've tried this could below but its not working well. Thank you for your great help.

    Function protectSheet()
        ThisWorkbook.Sheets("User").Protect Password:="trial", true, true
    End Function
2

2 Answers

2
votes

The problem with your code is you are using function instead of sub :) Rest you seem to be Good. Thanks

0
votes

Use this sub.

Sub shtProtect()
   Sheet1.Protect Password:="trial" 'Use your sheet name instead Sheet1
End Sub