Skip to content

How to Hide and Lock VBA Code in Excel

To hide and lock VBA code in Excel, set a password on your VBA project in the Visual Basic Editor, then compile the workbook into an EXE with XLS Padlock so the file is encrypted and password-removal tools cannot reach it. Excel’s native VBA password on its own is weak; XLS Padlock is what makes it hold.

XLS Padlock offers a dedicated Lock VBA Project feature. However, if you choose not to use it, you can still use Excel’s native protection. XLS Padlock makes this method more secure.

  1. In Excel, open the Visual Basic Editor (VBE) by pressing Alt+F11 or selecting it from the Developer tab.
  2. In the VBE, go to the Tools menu and select VBAProject Properties….
  3. In the dialog box, go to the Protection tab.
  4. Check the box for Lock project for viewing and enter a strong password.

Once the workbook is saved and reopened, users will be unable to view or edit the VBA code without the password.

Normally, Excel’s VBA password protection is considered weak because many tools exist that can remove the password. These tools work by directly accessing the Excel file.

However, when your workbook is compiled into an EXE with XLS Padlock, the original .xls or .xlsm file is encrypted and embedded within the application. Password-cracking tools cannot access this secured file, making them useless. This combination provides a much stronger defense for your VBA code.