Locking VBA project with code

KitaYama

Well-known member
Local time
Today, 16:18
Joined
Jan 6, 2022
Messages
2,065
The title says it all.

Is it possible to lock/unlock VBA project of a accdb file with code (vba)?

Thanks.
 
Just off the top of my head (can't do any testing right now), but probably possible from an external app.
 
I'd appreciate if you have any code for that.
Not in a hurry. Whenever you have enough free time to check.

Thanks.
 
I think it only works with SendKeys or something similar.

Locking:

The best lock is a compiled file (accde).
 
Last edited:
Danke schön @JosefP.
I knew I had answered the question before but hadn't searched for the link

@KitaYama
Although it can be done, do note the many caveats mentioned in that thread
1. It requires the use of SendKeys and the characters required are language dependant
2. VBA password protection is easily bypassed
3. Even when locked, a list of all procedures together with arguments is still accessible unless you use Option Private Module
4. Option Private Module is only available for Standard/Class Modules. A list of procedures etc in Form/Report modules is still visible.

Taken together, locking a project is of limited value and I rarely bother.
Use it as one part of a set of security measures but don't rely on it alone
 
@Josef P. @isladogs

I’m aware of the risks and how locking a vba project is of a limited value.
I was reading @isladogs’ security article and testing one of his demo databases.
Disabling shift by pass, hiding navigation pane and editing start up properties was done with code. I just wondered why I couldn’t find any code for locking the project.
My question was out of curiosity and not that I‘m planing to use it.

Thanks for solving the puzzle.
 
The article deliberately leaves out several details. Partly because I don’t want to provide information to help hackers. I also avoid the use of SendKeys wherever possible.
 
Counter-question: What is the special background to the desire for lock/unlock? A new front end is simply exchanged.
Design changes at runtime by the user are regularly an expression of previous deficiencies in the application.
The developer himself does not have to temporarily lock and therefore unlock anything.
 
I think it only works with SendKeys or something similar.
only :)

Just stumbled across this by accident while looking for something else in the WizHook class:
WizHook.SetVbaPassword
SendKeys is therefore not required for setting.

Looked up Thomas WizHook collection for safety:
 
I wrote an updated article about the Wizhook object last year which builds on the excellent information by Thomas Moller

The Wizhook.SetVBAPassword function does allow you to set the vba project password where it is blank but it does not allow you to change an existing password. Therefore it is less useful than it could have been.
 

Users who are viewing this thread

Back
Top Bottom