How to Protect VBA Code From Being Copied
Published: 2026-06-27 · Last reviewed: 2026-06-27 · By Noam Brand, founder, Excel Armor
Why the obvious method does not work
Almost everyone starts with Tools → VBAProject Properties → Protection → Lock project for viewing, sets a password, and assumes the code is safe. It is not. That password does not encrypt the code, it sets a flag that tells the Visual Basic Editor to hide the project. The macros are still stored, in full, inside the file. Free utilities, or a couple of minutes with a hex editor, remove the flag and reveal everything. The "VBA project unviewable" trick is the same idea with a different flag, and fails the same way. We cover the mechanics in why the VBA password is not protection.
The lesson: if the source is still in the file, it is not protected. Real protection has to take the source out of the artifact you hand to your users.
The four steps that actually protect VBA
- Stop treating the password as security. Keep it if you like for tidiness, but assume anyone who wants the code can read it as long as the VBA is in the file.
- Remove the source from the shipped file. Convert your VBA business logic to .NET source and compile it. Once compiled, the original VBA no longer exists in what you distribute, there is nothing to "unlock."
- Obfuscate the compiled code. Apply industry-standard .NET IL obfuscation so that even decompiling the assembly yields tangled, hard-to-read output rather than your clean logic.
- Sign it and control distribution. Code-sign the add-in with your own certificate so Windows and your customers trust it, and add licensing hooks so a single purchase cannot be freely passed around.
The result is a native Excel XLL add-in that behaves like any other add-in for your users, while the valuable logic ships as compiled, obfuscated machine-level code instead of readable VBA.
Do you have to rewrite everything in .NET?
No. The practical approach keeps your UI in VBA (Ribbon, UserForms, the parts that are tedious to rebuild) and moves only the business logic out to compiled .NET. A migration tool does the VBA-to-VB.NET conversion for you. Excel Armor's Migrator, for example, converts the logic and produces a ready-to-compile MSBuild project, and the Armor step packages, obfuscates, and prepares it for signing. You stay in control of the readable VB.NET source.
What protection cannot do
No method makes reverse-engineering impossible. A determined, well-resourced attacker can attempt to deobfuscate compiled .NET. The goal is not perfection, it is raising the cost of copying past the point where it is worth it for the realistic threats: resold workbooks, lifted formulas, code taken by a departing employee. Compiling and obfuscating moves that cost from "free tool, a few seconds" to "expert, many weeks." Any product that promises "uncrackable" is overselling, and that is a reason to be skeptical of it.
See where your workbook stands
Take the free 2-minute self-assessment, or read the security guide that walks through every protection method in plain language.
Free VBA protection check Download security guide (PDF)Related reading
- Best ways to protect VBA code in 2026, ranked
- Why the built-in VBA password is not protection
- Can VBA really be protected? What works and what does not
- How to stop people copying your Excel macros
- Excel Armor pricing & founding launch offer
Published by Excel Armor, which sells a VBA protection tool and therefore has a commercial interest in your conclusion. The technical claims above are about how Excel and VBA actually work and are verifiable independently. Spot an error? Tell us.