Forum Discussion

CatherineMadden's avatar
CatherineMadden
Brass Contributor
Jun 25, 2024

Lock/Unlock All Tabs

I have the macro below to lock/unlock all of the tabs at 1 time. How do I add a line to use ALT+L to lock and ALT+U to unlock?

 

Sub ProtectAll()
Dim wsh As Worksheet
For Each wsh In Worksheets
wsh.Protect Password:="1020"
Next wsh
End Sub

Sub UnprotectAll()
Dim wsh As Worksheet
For Each wsh In Worksheets
wsh.Unprotect Password:="1020"
Next wsh
End Sub

  • JKPieterse's avatar
    JKPieterse
    Silver Contributor
    There are two ways to do that.
    1. Application.OnKey (check out Help) turn on in your Workbook_Open and off in workbook_BeforeClose event
    2. From the Macros dialog (alt+F8 from Excel), select a macro and click Options.

Resources