About the built-in VBA compiler


VBA Code Protection > About the built-in VBA compiler

XLS Padlock features an integrated VBA compiler: you can write Basic scripts and compile them into working byte-code not accessible to final users.

Turning parts of your VBA macros into compiled code allows you to secure them: the original code does not exist anymore, and it cannot be copied.


For a tutorial about compiling a VBA function, you can watch this video:



For instance, see this original code:

Once protected, it becomes:

As you can see, the original code in calculate() has been replaced by a call to XLS Padlock’s built-in function named PLEvalVBA. This function executes the compiled bytecode.

The original code of calculate() has been moved into XLS Padlock VBA Editor and compiled there, as you can see below:

Comparing to the original code above, we had to make some modifications: indeed, the compiler requires the use of the Application object to access Excel objects (see Accessing Excel objects from compiled VBA code).

Writing and compiling secure VBA code

Application’s properties and methods accessible by the XLS Padlock VBA compiler are described in Microsoft Office Dev Center documentation: http://msdn.microsoft.com/en-us/library/office/ff194565.aspx

The compiler is not a simple obfuscator: it completely turns your VBA code into binary code and stores it securely in the application. Finally, you can optionally password protect your VBA project : since the original XLS file cannot be recovered, Excel password-cracking tools are useless.

Some limitations:

You may have to make changes to your original VBA code in order to compile it. The XLS Padlock VBA compiler is not as advanced as Microsoft VB interpreter.

Entire macros generally cannot be compiled: only parts of them.

Some objects and default properties are not accessible.


Copyright © 2021 G.D.G. Software