Password protect

ChrisFoster

Board Regular
Joined
Jun 21, 2019
Messages
246
Office Version
  1. 365
Platform
  1. Windows
Hi all,

Is there a way to have an excel document password protected (to open) but set it so if I'm the one opening it, it doesnt ask for the password?
So basically, I can access it but everyone else needs to use the password?

Cheers

Chris
 

Excel Facts

Add Bullets to Range
Select range. Press Ctrl+1. On Number tab, choose Custom. Type Alt+7 then space then @ sign (using 7 on numeric keypad)
Hi,​
it could be done without the password at workbook level - the safer - but it would be so easy to bypass - the worse - …​
 
Upvote 0
The only safe protection is the one at workbook level …

The kind of so call 'protection' you want can be done under VBA but it can be easily bypassed.
 
Upvote 0
The only safe protection is the one at workbook level …

The kind of so call 'protection' you want can be done under VBA but it can be easily bypassed.
Just a straight answer would work
 
Upvote 0
As the answer to your question depends on the security level you need …​
 
Upvote 0
You could use Environ(username) at Workbook_open, which could then close the workbook if it isn't you...
AND
you could Protect the VBA with a password as well.
BUT, passwords and security in Excel is fairly weak, so anyone that really wanted to look at your work could easily do so, if they knew how to look.
VBA Code:
Sub Workbook_Open()
If Environ("username") <> "YOURUSERNAME" Then 
MsgBox "Access to this workbook is not permitted?"
Application.Close
End Sub
 
Last edited:
Upvote 0
As the answer to your question depends on the security level you need …​
You're over complicating it for some reason, it's a really simple request.
I just want an excel workbook to have a password to open it, but if I'm the user opening it doesn't need the password. For anyone else opening it they would need the password.
 
Upvote 0
So like Michael and I have stated it's possible with the lowest level of 'security',​
even a kid just reading some blog could bypass this kind of 'protection' …​
For the maximum security level, that's not possible, password at workbook level so anyone must enter it to access the workbook.​
 
Upvote 0
@ChrisFoster
If the security of the workbook is that important, I wouldn't be using Excel.
If Excel is the tool of choice, then the only way to do it would be to convert the file to an .exe file or addin
But......
This will open the workbook if your username is correct and ask for a password if it isn't.
As WE have stated security is very weak in Excel, but it will keep MOST honest people out !!
VBA Code:
Sub Workbook_Open()
Dim ans As String, Pwd As String
Pwd = "YOUR PASSWORD"
If Environ("username") <> "YOURNAME" Then
ans = InputBox("Please Insert your Password")
If ans <> Pwd Then
MsgBox "Access to this workbook is not permitted?"
Application.Close
End If
End If
End Sub
 
Upvote 0

Forum statistics

Threads
1,213,494
Messages
6,113,988
Members
448,538
Latest member
alex78

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top