VBA - Verify "Open password"

Ravion

New Member
Joined
Jan 13, 2012
Messages
2
Hello guys,

before I get misunderstood I'll make it clear. This is not a thread about hacking/cracking Excel/VBA passwords, the situation follows:

I have a project in Excel and it contains some sensitive data, it's not top secret but I'd like to avoid anyone beeing able to open the file and read the content. For this purpose I set 2 passwords, one for "Open" and another for "Write", both are Workbook's property (ActiveWorkbook.Password) and (ActiveWorkbook.WritePassword). However, this file won't be used just by me and I'd like to write a VBA code so that the User can change the password as he wants. The code for setting the password is really simple and I already have it:

Code:
Dim strOPW as string, strWPW as string
 
'inputbox or form
 
ActiveWorkbook.Password = OPW
ActiveWorkbook.WritePassword = WPW

But there is something bothering me: Excel doesn't ask you the current password, he just changes it without questioning and that's a big problem imo. I tried to write a code to get the current password, so I can verify if they match and only then, change the password. I tried:

Code:
verOPW = ActiveWorkbook.Password
verWPW = ActiveWorkbook.WritePassword

but if I try to compare the current open password and the content of verOPW, for exemple, I get always "FALSE" and if I try to read the value of verOPW, all I get is *******.

So I'd like to kindly ask if someone knows how could I make this verification with the current password before I set one anew.

Thanks in advance and best regards!
 

Excel Facts

Using Function Arguments with nested formulas
If writing INDEX in Func. Arguments, type MATCH(. Use the mouse to click inside MATCH in the formula bar. Dialog switches to MATCH.
Welcome to MrExcel.

Surely the user already knows the existing passwords because he opened the workbook? The properties don't return the actual password, but a string of *s.
 
Upvote 0
Hello Andrew, thanks for the Welcome!

You are right, the User knows the password but it is a security matter. In theory nothing prevents someone unauthorized, e.g. who finds the file open, to change the password. I know and I agree that sounds a little paranoia, but it's company policy.
 
Upvote 0

Forum statistics

Threads
1,215,056
Messages
6,122,907
Members
449,096
Latest member
dbomb1414

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