ACM
12-21-2010, 09:36 AM
Okay, so currently I have this code:
Option Explicit
Sub UnlockAllSheets()
'Unlocks all worksheets in workbook
Dim i As Integer
On Error Resume Next
For i = 1 To Sheets.Count
Worksheets(i).Unprotect Password:="password" 'Change to your password here
Next i
End Sub
'Locks all worksheets in workbook
Sub LockAllSheets()
Dim i As Integer
On Error Resume Next
For i = 1 To Sheets.Count
Worksheets(i).Protect Password:="password" 'Change to your password here
Next i
End Sub
At the moment, I'm just using two separate buttons to lock/unlock all sheets in the workbook. How do I merge this code into one so the same button unlocks/locks the sheets?
Option Explicit
Sub UnlockAllSheets()
'Unlocks all worksheets in workbook
Dim i As Integer
On Error Resume Next
For i = 1 To Sheets.Count
Worksheets(i).Unprotect Password:="password" 'Change to your password here
Next i
End Sub
'Locks all worksheets in workbook
Sub LockAllSheets()
Dim i As Integer
On Error Resume Next
For i = 1 To Sheets.Count
Worksheets(i).Protect Password:="password" 'Change to your password here
Next i
End Sub
At the moment, I'm just using two separate buttons to lock/unlock all sheets in the workbook. How do I merge this code into one so the same button unlocks/locks the sheets?