简体   繁体   中英

Protecting a worksheets using a password in excel 2013 using VBA

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

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

Use this sub.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM