andyreloaded
Board Regular
- Joined
- Aug 1, 2006
- Messages
- 80
I have a spreadsheet with 50 or so tabs that I want to protect and unprotect with a macro. So when I run the LOCK macro, it prompts once for a password, then cycles through all the sheets locking them with that password. And when I run the UNLOCK macro, it prompts once for my password, then cycles through all the sheets unlocking them with that password.
Here is what I have so far, but it has the password actually coded into the macro instead of prompting. Thanks for all your help, as always!
LOCK
Sub LockFormulas()
Dim WkSht As Integer
For WkSht = 1 To Worksheets.Count
With Sheets(WkSht)
On Error Resume Next
.Cells.Locked = False
.Cells.SpecialCells(xlCellTypeFormulas, 23).Locked = True
.Protect "mypassword"
Err.Clear
End With
Next WkSht
End Sub
UNLOCK
Sub UnlockFormulas()
Dim WkSht As Integer
For WkSht = 1 To Worksheets.Count
With Sheets(WkSht)
.Unprotect "mypassword"
End With
Next WkSht
End Sub
Here is what I have so far, but it has the password actually coded into the macro instead of prompting. Thanks for all your help, as always!
LOCK
Sub LockFormulas()
Dim WkSht As Integer
For WkSht = 1 To Worksheets.Count
With Sheets(WkSht)
On Error Resume Next
.Cells.Locked = False
.Cells.SpecialCells(xlCellTypeFormulas, 23).Locked = True
.Protect "mypassword"
Err.Clear
End With
Next WkSht
End Sub
UNLOCK
Sub UnlockFormulas()
Dim WkSht As Integer
For WkSht = 1 To Worksheets.Count
With Sheets(WkSht)
.Unprotect "mypassword"
End With
Next WkSht
End Sub