Can VBAProject Properties password be set through VBA Workbook_Open()

rjheibel

New Member
Joined
Mar 8, 2018
Messages
42
I am trying to think of a way to stop someone from removing the password from the VBAProject Properties by modifying the VbaProject.bin file once unzipped. My thought would be to add code to my Workbook_Open that would check if the VBAProject Properties has a password, and if it does not, add a password to it. Is something like this possible?
 

Excel Facts

Last used cell?
Press Ctrl+End to move to what Excel thinks is the last used cell.
I can't speak to the possibility of anyone removing the project password by modifying the bin file. However, if startup code can be bypassed then the code generated password is visible to anyone. If you intend to use Auto__Open sub then it definitely could be exposed. Anyone who has a basic understanding should be able to prevent code from running just by disabling macros in the application Trust Center settings, thereby exposing the code another way. If it is likely that your file will be subjected to that level of hacking (using a hex editor?) then I wonder if your choice of application is the right one.
 
Upvote 0
I am trying to think of a way to stop someone from removing the password from the VBAProject Properties by modifying the VbaProject.bin file once unzipped. My thought would be to add code to my Workbook_Open that would check if the VBAProject Properties has a password, and if it does not, add a password to it. Is something like this possible?
This post may be helpful...https://www.mrexcel.com/board/threads/lock-unlock-vbaprojects-programmatically-without-sendkeys.1136415/
 
Upvote 0
This post may be helpful...https://www.mrexcel.com/board/threads/lock-unlock-vbaprojects-programmatically-without-sendkeys.1136415/
I can't seem to get that to work and that code is way over my head. I have tried to use sendkeys command to set the password but have not been able to get this to work. Can anyone give me pointers of what I am doing wrong? When I try to run the code below, I get a large crosshair that shows the numerical mouse position (see pic).

VBA Code:
Sub SetPassword()


SendKeys "%{F11}"
SendKeys "%T"
SendKeys "+E"
SendKeys "{ENTER}"
SendKeys "+{TAB}"
SendKeys "{RIGHT}"
SendKeys "{TAB}"
SendKeys "{TAB}"
SendKeys "", True
SendKeys "%P"
SendKeys "Password"
SendKeys "{TAB}"
SendKeys "Password"
SendKeys "{Enter}"


End Sub
 

Attachments

  • Untitled.png
    Untitled.png
    13.1 KB · Views: 3
Upvote 0
I've put the code into a blank workbook for you to try out. To add this to your own workbook, copy module 1 code to a module in your workbook, then you can use the subs in Sheet1 to programmatically lock/unlock the project.

In order for this to work you'll need to change a setting (Trust Access to the VBA project object model) in Excel as follows:
1698779747799.png


 
Upvote 0

Forum statistics

Threads
1,215,143
Messages
6,123,285
Members
449,094
Latest member
GoToLeep

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