0

I couldn't find an answer anywhere and I have the feeling that it's not possible, but it can't hurt to ask :).

I'm creating an Excel file via a .NET forms app and I added some vba code to the file. I don't want people to mess with it, so I want to put a password on the vba project, but I can't find how to do it. It seems that VBProject.Protection is read only.

I also tried to unzip the Excel file to see what the difference is in the xl/vbaProject.bin file after I added a password manually. Although most if it is unreadable, I noticed a line that started with "DPB=" and the value of the password protected project was much longer. However, the unprotected file got corrupted when I copied the value from the protected file.

Does anyone have any experience with automatically protect VBProjects?

I really appreciate any help!

Alex de Jong
  • 1,257
  • 1
  • 11
  • 23
  • Why bother if one can [remove this protection](https://stackoverflow.com/questions/1026483/is-there-a-way-to-crack-the-password-on-an-excel-vba-project) within seconds? – Storax Mar 28 '20 at 16:57
  • Most of all it just needs to be idiot proof. The code is not really exiciting but I just don't want hobbyist changing it "by accident" and then I need to help them out. – Alex de Jong Mar 28 '20 at 17:13
  • Maybe with the use of API which catch the windows and you add a password that way. Or you use the not very reliable way and send keys like described [here](https://stackoverflow.com/questions/53323655/locking-a-project-programmatically-in-vba). – Storax Mar 28 '20 at 17:47
  • Can you start with a template containing a protected VB project and your code ? – Tim Williams Mar 28 '20 at 19:09
  • This can be easily achieved using APIs. – Siddharth Rout Mar 29 '20 at 05:51
  • There is a solution with API in VB: https://stackoverflow.com/a/16176557/5122172 – user5122172 Dec 13 '21 at 09:54

0 Answers0