Skip to content

Writing and Compiling Secure VBA Code

You can protect sensitive parts of your VBA code by compiling them into bytecode with XLS Padlock. We recommend combining compiled bytecode with your existing VBA code for a balanced approach to security and development.

  1. In Excel, click “VBA Compiler and Protection” to open the XLS Padlock VBA Editor and Compiler:

    XLS Padlock toolbar in Excel with the VBA Compiler and Protection button highlighted

    The XLS Padlock VBA editor will open:

    XLS Padlock VBA editor and compiler window with the code text area and Compile Code button

  2. In the text area, enter the VBA code you want to compile. You can group your code into subs and functions. To simplify this process, you can open the Visual Basic Editor by clicking “Show Visual Basic Editor” and copy/paste your code.

    By default, all subs and functions have one parameter named Param1. However, you can use more parameters.

  3. When you are done, click “Compile Code”. The VBA code is instantly compiled into bytecode, which XLS Padlock will store until you compile your application EXE file.

  1. Click “Save and close” to close the editor.

👉 After compiling your code, you will need to modify your original VBA macros to call the compiled version. Learn how to do so in the Invoking Compiled VBA Code at Runtime guide.