Password Potect through VBA from Cell

JBruner79

New Member
Joined
Nov 10, 2017
Messages
7
So I am trying to password protect my workbook so that it won't open unless you have the password. But here's what i need:

I need to have a cell that contains the password so that it can be changed whenever and easily for someone who has no excel or computer literacy, without going through settings.
I need code to only open workbook if password entered matches what is in the cell.

Is there a way to do this? I have looked and can't figure it out. So any help would be greatly appreciated.
Thank you!!!
 

Excel Facts

Remove leading & trailing spaces
Save as CSV to remove all leading and trailing spaces. It is faster than using TRIM().
If the password is in a cell that is easily accessible, what's the point, as anyone can what the password is?
 
Upvote 0
If the password is in a cell that is easily accessible, what's the point, as anyone can what the password is?

There are 5 people who need access, so the password it to keep everyone else out. It doesn't matter if the other 5 know the pw.
 
Upvote 0
But if the password is in a cell what's to stop everyone else looking at it?
 
Upvote 0
Because it wouldn't be used by everyone in the office, just the managers. I honestly didn't think when I was asking for help that I would receive such interrogation. Its a need I have, and can't figure it out myself. It really doesn't matter if you agree with the why its needs to be this way, or if you understand why. I am here like everyone else, asking for guidance so that I can learn and improve my skillset, at the same time provide my office with the resources they need.
 
Upvote 0
Code:
Private Sub CommandButton1_Click()
Dim wb As Workbook
Dim psswd As String
psswd = InputBox("enter password")
Set wb = Workbooks.Open(Filename:="password.xlsx", Password:=psswd)
End Sub

and here is the save macro:

Code:
Sub PasswordSave()
Application.DisplayAlerts = False
Application.ScreenUpdating = False


ActiveWorkbook.SaveAs Filename:="c:\Put_Path_Here\password.xlsx", FileFormat:= _
xlNormal, Password:=Sheets("password").Range("A1").Value, WriteResPassword:=Sheets("password").Range("A1").Value, ReadOnlyRecommended:=False _
, CreateBackup:=False
ActiveWorkbook.Close
End Sub

the problem in doing so is that if the user types a new password in A1, saves it and forget's it, then the file cannot be recovered (except using third party tools)
 
Upvote 0
Because it wouldn't be used by everyone in the office, just the managers. I honestly didn't think when I was asking for help that I would receive such interrogation.
He is simply trying to make you aware that the method that you propose won't be sure at all, which kind of defeats the purpose of password protecting (what is the sense in password protecting if the password is readily visible to all?).

Sometimes, the question isn't quite clear, so we need more details to fully understand it. Remember, we are not familiar with your problem, all that we have to go on is what you provide here. So, if the question is lacking in detail, we often need more information to fully understand the question and provide a solution. It is not an "interrogation", it is simply trying to gather the necessary information to provide you with a solution (don't bite the hand that is trying to feed you!).

Many times people ask questions and they get stuck on an idea that won't really accomplish what they are trying to do. If we have a clear understanding of what the ultimate goal is, we can often offer alternative solutions that will accomplish that goal, instead of providing solutions based on faulty logic.
 
Last edited:
Upvote 0
Put this in the ThisWorkbook module
Code:
Private Sub Workbook_Open()
   Dim Pwrd As String
   
   Pwrd = InputBox("Please enter a password")
   If Pwrd <> Sheets("sheet1").Range("A1").Value Then
      ThisWorkbook.Close False
   End If
   
End Sub
But if someone changes their macro settings, or opens the file in safe mode, it won't work.
 
Last edited:
Upvote 0

Forum statistics

Threads
1,223,236
Messages
6,170,915
Members
452,366
Latest member
TePunaBloke

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