Best way to protect Excel VBA code?

Solution 1:

You can create Automation Add In.

An Automation Add In provides several advantages

  • Execution Speed : An Automation Add In written in VB6 is compiled to native machine code which runs much faster than the interpreted VBA languange.

  • Security : Unlike an XLA add in, you never distribute the source code to the end users. If your code has proprietary information or intellectual property value, that remains safely protected on your own computer. It is never distributed to the user. Your code can never be compromised.

http://www.cpearson.com/excel/automationaddins.aspx

Solution 2:

There aren’t too many ways to protect your Excel VBA code reliably.

You can try to use passwords or VBA obfuscators, but all of that protection is limited. Passwords are easy to break, and obfuscated VBA code can still be traced back and recovered.

The other answer to this question mentions using VB6, but that limits your code to 32bit Excel. Also VB6 can be decompiled by VB decompiler.

Converting your code to a compiled language is indeed the best way to protect your VBA code, but be warned that in this case not all code is created equal.

Converting your code to VBA.NET is a flawed solution because the compiled code of .NET assembly can be converted back into the original source code.

Converting your VBA code to C or C++ is the most effective form of protection, but this takes a lot of experience and effort since C/C++ and VBA are very different languages.

I would suggest you have a look at a tool called VBA Compiler for Excel (https://vbacompiler.com/how-to-compile/). It compiles your Excel VBA code into a DLL file with a click. You do not need any knowledge of C or C++ languages to use it.