Excel 2010 - Password Protection

I'm very intrigued with password protection with Excel. Though I had a few questions in that regard. 

I am using Excel 2010, and just realized there is a Password Protection option. This apparently has been available for a few versions. Though I am in not much need of it at the moment. But still am curious. 

Compared to the VBA code below.. what is the difference between the code, and setting it by Excel? Is the Code any more Secure than Excel's?
Since you cannot actually see Excel's code.

Private Sub Workbook_BeforeClose(Cancel As Boolean)
 ActiveWorkbook.Password = "Password"
End Sub

I know that if you open VBA, you'll see this code (if you can figure out the password, or use a password disable software), and I know that if you use the VBA Protection, you can prevent anyone from seeing Code, if there is any, unless using a password. 



What code would I use to Password Protect individual Worksheets without having code between the ActiveSheet.Protect/unprotect?
And if there is code, where exactly would I need to put the ActiveSheet.Protect/Unprotect at?

And would all of this be compatible with 2007 and 2010 on XP/7?

Just for the heck of it, I want to password protect a workbook like the Pentagon. 
Plus this is a great learning experience. 

Thanks for reading. 

Question Info

Last updated February 21, 2018 Views 2,047 Applies to:

Hi, that is because the password is in the code

ws.Protect Password:="geo"

you can change it for yours

if for example you want to unhide a sheet that is password protected and you want to be asked for the password you have an example here


Private Sub Worksheet_Activate()
Dim strPassword As String
On Error Resume Next
Me.Protect Password:="MANAGER"
Me.Columns.Hidden = True
strPassword = InputBox("Enter password to access DATA sheet")
If strPassword = "" Then
ActiveSheet.Visible = False
Exit Sub
ElseIf strPassword <> "MANAGER" Then
MsgBox "Password Incorrect "
ActiveSheet.Visible = False
Exit Sub
Me.Unprotect Password:="MANAGER"
Me.Columns.Hidden = False
End If
On Error GoTo 0
End Sub
Private Sub Worksheet_Deactivate()
On Error Resume Next
Me.Columns.Hidden = True
On Error GoTo 0
End Sub



If this post is helpful or answers the question, please mark it so, thank you.

Did this solve your problem?

Sorry this didn't help.

Great! Thanks for marking this as the answer.

How satisfied are you with this reply?

Thanks for your feedback, it helps us improve the site.

How satisfied are you with this response?

Thanks for your feedback.