marigold322
New Member
- Joined
- Mar 9, 2023
- Messages
- 6
- Office Version
- 365
- Platform
- Windows
Hi there,
I have been using macros to protect/unprotect all the sheets in my workbook. I'll leave both codes below for your reference.
I just recently learned that macros can be added into the quick access toolbar (QAT), and so I thought this would be perfect to save me time opening the developer and running the macros manually. Unfortunately I discovered that running macros from the QAT is just opening the first workbook I tried this on (tried adding the macros to the QAT). So when I open a workbook and use the icon, it runs the macro on an original workbook.
Is there a way to edit these macros so that they can be run from my QAT but will only protect/unprotect the sheet i am working on?
Any advice is appreciated, please let me know if I can clarify any part of my inquiry or if anything is unclear. Thank you kindly for your time.
PROTECT:
UNPROTECT:
I have been using macros to protect/unprotect all the sheets in my workbook. I'll leave both codes below for your reference.
I just recently learned that macros can be added into the quick access toolbar (QAT), and so I thought this would be perfect to save me time opening the developer and running the macros manually. Unfortunately I discovered that running macros from the QAT is just opening the first workbook I tried this on (tried adding the macros to the QAT). So when I open a workbook and use the icon, it runs the macro on an original workbook.
Is there a way to edit these macros so that they can be run from my QAT but will only protect/unprotect the sheet i am working on?
Any advice is appreciated, please let me know if I can clarify any part of my inquiry or if anything is unclear. Thank you kindly for your time.
PROTECT:
VBA Code:
Sub ProtectAllSheets()
Dim ws As Worksheet
Dim password As String
password = "Medavie"
For Each ws In Worksheets
ws.Protect password:=password
Next ws
End Sub
UNPROTECT:
Code:
Sub unprotect_all_sheets()
On Error Goto booboo
unpass = InputBox("Please enter the password:")
For Each Worksheet In ActiveWorkbook.Worksheets
Worksheet.Unprotect Password:=unpass
Next
Exit Sub
booboo: MsgBox "There is s problem - check your password, capslock, etc."
End Sub