Hello,
I have gotten this far, but need a little more help. I have 2 buttons 1 to protect a sheet, and 1 to unprotect a sheet. I have recorded the macros, but I want the macro to request a password for each.
what is the next step?
Excel 2007.
Thanks, Brad
Sub Protect()
'
' Macro2 Macro
ActiveSheet.Protect DrawingObjects:=True, Contents:=True, Scenarios:=True
End Sub
Sub Unprotect()
'
' Macro3 Macro
ActiveSheet.Unprotect
End Sub
Protect and Unprotect using Macros
-
- 4StarLounger
- Posts: 545
- Joined: 30 Mar 2010, 18:49
- Location: United States
-
- Administrator
- Posts: 78631
- Joined: 16 Jan 2010, 00:14
- Status: Microsoft MVP
- Location: Wageningen, The Netherlands
Re: Protect and Unprotect using Macros
Code: Select all
Sub Protect()
Dim strPassword As String
strPassword = InputBox("Please provide the password")
ActiveSheet.Protect DrawingObjects:=True, Contents:=True, Scenarios:=True, Password:=strPassword
End Sub
Sub Unprotect()
Dim strPassword As String
strPassword = InputBox("Please provide the password")
On Error GoTo ErrHandler
ActiveSheet.Unprotect Password:=strPassword
Exit Sub
ErrHandler:
MsgBox "Wrong password!", vbExclamation
End Sub
Best wishes,
Hans
Hans
-
- GoldLounger
- Posts: 2631
- Joined: 26 Jan 2010, 16:31
- Location: Southern California
Re: Protect and Unprotect using Macros
Here is an example of masking the password with **********
A sample file is attached along with the code in the form.
Regards,
John
A sample file is attached along with the code in the form.
Regards,
John
You do not have the required permissions to view the files attached to this post.
Regards,
John
John
-
- 4StarLounger
- Posts: 545
- Joined: 30 Mar 2010, 18:49
- Location: United States
Re: Protect and Unprotect using Macros
way cool for both inputs....
Thanks much,
Brad
Thanks much,
Brad