Link to home
Start Free TrialLog in
Avatar of philosopher76
philosopher76Flag for Mexico

asked on

How to lock/unlock a worksheet/workbook with a defined password using a macro in excel?

I would like to save time opening and closing my file and I would like to run a macro to do so.

Thanks!
ASKER CERTIFIED SOLUTION
Avatar of Roy Cox
Roy Cox
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
To re-protect the sheets when closing place this code in the WorkBook close event

Option Explicit

Private Sub Workbook_BeforeClose(Cancel As Boolean)
 Dim ws As Worksheet
        For Each ws In ActiveWorkbook.Worksheets
        ws.Protect "YourPassworsd"
    Next ws

End Sub

Open in new window


The workbook will still have it's protection unless you remove it