简体   繁体   中英

VBA Protect Function Applies the Wrong Password

I start the Workbook_Open event with this line of code

Table1.Protect Password = "Secret", UserInterFaceOnly:=True

However, when I try to unlock it with

Table1.Unprotect ("Secret")

it does not work.

The Password Cracker says, that a working password would be "AAAAAAAABABF"

How do I actually set "Secret" as the password.

It's a common mistake (so common I wrote this: http://excelmatters.com/2013/10/03/whats-in-a-colon/ ).

Your Protect code is missing a colon:

Table1.Protect Password:="Secret", UserInterFaceOnly:=True

You were actually protecting the workbook with the password False, since that's the result of the expression:

Password = "Secret"

TL;DR Read the article that Rory wrote (in his answer below)

Firstly, your protect code is wrong (missing a colon : ):

Table1.Protect Password = "Secret", UserInterFaceOnly:=True

This is assigning Password which will be treated as an undeclared variable (did you forget to use Option Explicit ?)

It should be this:

Table1.Protect Password:= "Secret", UserInterFaceOnly:=True

The Password Cracker says, that a working password would be "AAAAAAAABABF"

This is because these kinds of passwords in Excel are not secure (this is well documented). Passwords of this nature in Excel rely on more of a numerical value where each character is assigned a numeric value... so:

d = 4
a = 1

(a + a + a + a) = d

and so in this case using d or aaaa would work as your password. (This is a crude example of how it works, not the exact methods).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM