Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Best way to protect Excel VBA code?

I've put together a simple Excel database that performs a few macro functions and I need to distribute this database to a few people - but they cannot see how the macro function actually works (stupid rules I have to follow!). What is the best way to achieve this?

I've done a bit of research and I found two ways:

  • Password protect the VBA project; but this is apparently very easy to break using readily available tools online (it would be in the best interest to the people I'm sending this to find out how the macros and functions work; so I'm almost 100% sure they will try to get into it.. hence a password protection seems inadequate.

  • Move to a fully compiled language like C++; my skills are very limited to VBA on Excel and Access so this being the ideal solution; isn't a solution for me :(

Are there any other ways? I thought of having a 'master excel document' with all the macros in that and then send 'children' databases to the end users and have the 'children' databases connect to the 'master' - is something like this possible? By hosting the master online or even sending the end users the master but making it completely inaccessible unless accessed by the 'children' databases?

like image 776
Chronix3 Avatar asked May 26 '13 07:05

Chronix3


People also ask

Can you password protect VBA code?

You can prevent users from viewing your code by locking any VBA project associated with your MS-Office solution. On the Protection tab, select the Lock project for viewing check box. Enter and confirm a password. Click OK.

Is VBA Excel secure?

You can protect your VBA projects with passwords although your code is not 100% secure. Adding a password will deter the average user though. You can protect your code by locking the project for viewing and providing a password (Tools > VBAProject Properties)(Protection tab, "Lock project for viewing").


2 Answers

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.

like image 177
NikoDeem Avatar answered Oct 15 '22 12:10

NikoDeem


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

like image 8
Santosh Avatar answered Oct 15 '22 10:10

Santosh