Skip to content

VBA Compatibility

VBA Padlock compiles VBA (Visual Basic for Applications) into protected bytecode executed inside your secured DLL.

Use this page as your practical compatibility guide: what works, what does not, and what to adapt when moving from standard Office VBA to compiled scripts.

VBA Padlock code editor with VBA script modules

AreaStatusNotes
Core VBA language (Dim, loops, procedures, arrays, Enum, Type)✅ Fully supportedIncludes dynamic arrays and recursion
Built-in VBA functions✅ Broad coverageSee Script Functions Reference
Office object model (Application)✅ Fully supportedUse explicit Application. prefix in protected code
COM automation (CreateObject)✅ SupportedScripting.Dictionary, ADODB.*, etc.
Windows API Declare⚠️ Opt-inDisabled by default; enabled on request — see DLL Calls
Class modules / UserForms❌ Not supportedUse standard modules + Padlock dialogs
FeatureSupportedNotes
Variables (Dim, Private, Public)YesAll standard data types
Constants (Const)Yes
Arrays (fixed and dynamic)YesReDim, ReDim Preserve supported
User-defined types (Type)Yes
Enumerations (Enum)Yes
Option ExplicitYesRecommended
Option CompareYesBinary and Text
Comments (' and Rem)Yes
TypeSupportedNotes
BooleanYes
ByteYes
IntegerYes
LongYes
LongLongYes64-bit integer
SingleYes
DoubleYes
CurrencyYes
StringYesVariable-length strings
DateYesStored as Double internally
VariantYesFull support
ObjectYesCOM objects via Application and CreateObject()
FeatureSupported
If...Then...Else...End IfYes
Select CaseYes
For...NextYes
For Each...NextYes
Do...Loop (While/Until)Yes
While...WendYes
GoToYes
GoSub...ReturnYes
On Error GoToYes
On Error Resume NextYes
Exit Sub/Function/For/DoYes
EndYes
FeatureSupportedNotes
SubYes
FunctionYes
Property Get/Let/SetYes
Optional parametersYes
ParamArrayYes
ByRef / ByValYesByRef is default
Recursive callsYes
Declare (DLL calls)Opt-inDisabled by default; see DLL Calls
Module-level codeYesExecuted on module initialization

All standard VBA operators are supported:

  • Arithmetic: +, -, *, /, \ (integer division), Mod, ^
  • Comparison: =, <>, <, >, <=, >=
  • Logical: And, Or, Not, Xor, Eqv, Imp
  • String: & (concatenation), Like (pattern matching)
  • Other: Is, IsNot, TypeOf...Is

VBA Padlock includes a comprehensive set of built-in functions that mirror standard VBA functions. See the Script Functions Reference for the complete list, including:

  • String functions (Mid, Left, Right, InStr, InStrRev, Replace, Split, Join, Trim, LTrim, RTrim, UCase, LCase, StrComp, StrReverse, Chr, ChrW, Asc, AscW, Hex, Space, String, Format)
  • Math functions (Abs, Sqr, Sin, Cos, Tan, Exp, Round, Int, Fix, Sgn, Rnd)
  • Date functions (Now, Date, Time, DateAdd, DateDiff, Weekday, WeekdayName, MonthName, Year, Month, Day, Hour, Minute, Second)
  • Type functions (TypeName, VarType, IsObject, IsMissing, IsArray, IsDate, IsEmpty, IsNull, IsNumeric)
  • Conversion functions (CInt, CLng, CDbl, CSng, CStr, CBool, CByte, CDate, CCur)
  • Flow functions (IIf, Choose, Switch)
  • Utility functions (Array, DoEvents, RGB, Nz, LBound, UBound, Randomize)

VBA Padlock ships with a rich set of ready-to-use script libraries containing thousands of Office constants and utility functions. These .bas template files can be added to your project via the Templates button and referenced from any module using the References directive.

See the Script Libraries & Constants reference for the full catalog of available libraries, usage instructions, and code examples.


Compiled scripts have full access to the host Office application through the Application object. You can manipulate worksheets, documents, presentations, and databases exactly as you would in regular VBA.

Protected code in VBA Padlock using the Office object model

Section titled “Protected code vs caller code (recommended workflow)”
  1. Write sensitive logic in protected modules (inside VBA Padlock Studio).
  2. Use explicit Application. references for host objects.
  3. Call protected routines from Office VBA through VBAPL_Execute(...).

These examples show how you should write your code inside the VBA Padlock Editor to ensure it can be compiled successfully:

' PROTECTED CODE (Inside VBA Padlock)
Sub WriteToCell(CellAddress, Value)
' Correct: uses Application.
Application.ActiveSheet.Range(CellAddress).Value = Value
End Sub
Function ReadFromCell(CellAddress)
' Correct: uses Application.
ReadFromCell = Application.ActiveSheet.Range(CellAddress).Value
End Function

On the other hand, the code you write in the Excel/Word VBA Editor (Alt+F11) acts as a simple bridge. It does not need any special prefixes:

' CALLER CODE (Inside Excel/Word VBE)
Sub RunMyProtectedCode()
' Regular VBA call to the compiled function
Call VBAPL_Execute("WriteToCell", "A1", "Hello!")
End Sub

Office VBA caller code invoking VBAPL_Execute

CreateObject() is supported in compiled scripts. You can create and use COM objects such as Scripting.Dictionary, ADODB.Connection, ADODB.Stream, etc.

Function RemoveDuplicates(ColumnIndex)
Dim Dict
Set Dict = CreateObject("Scripting.Dictionary")
Dim WS, LastRow, Row, Key
Set WS = Application.ActiveSheet
LastRow = WS.Cells(WS.Rows.Count, ColumnIndex).End(-4162).Row ' xlUp
For Row = 2 To LastRow
Key = CStr(WS.Cells(Row, ColumnIndex).Value)
If Not Dict.Exists(Key) Then
Dict.Add Key, Row
End If
Next Row
RemoveDuplicates = Dict.Count
End Function

These limitations are by design and keep the execution model secure and deterministic.

VBA Padlock supports standard VBA Declare statements to call functions in external DLLs (Windows APIs and third-party DLLs). The syntax is identical to regular VBA:

Declare Function GetTickCount Lib "kernel32" () As Long
Declare Function GetComputerNameW Lib "kernel32" (ByVal lpBuffer As String, ByRef nSize As Long) As Long
Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)

Class modules (Class blocks) are not supported. Use standard modules with Sub, Function, and Type definitions instead.

VBA UserForms are not available in compiled scripts. VBA Padlock provides its own built-in dialogs (activation, trial nag, EULA) configured through VBA Padlock Studio.

The Debug.Print statement is not available. Use DebugPrint (from the Extension Library) instead, which outputs to OutputDebugString — visible with tools like DebugView or Visual Studio’s Output window.

' Instead of Debug.Print:
DebugPrint "Value of x = " & x

VBAPL_Execute supports any number of parameters. Calls with 0 to 4 arguments use optimized dedicated DLL exports, while calls with 5 or more arguments are automatically packed into an array and routed through ExecuteVBAFunctionN. This is handled transparently.

' Call with few parameters
result = VBAPL_Execute("Main|CalculatePrice", quantity, unitPrice)
' Call with many parameters (no limit)
result = VBAPL_Execute("Reports|Generate", title, startDate, endDate, format, outputPath, includeCharts)

When omitting the module name (e.g., VBAPL_Execute("MyFunction", arg1)), the function is searched in the default Main script. To call a function in another module, use the "ModuleName|FunctionName" syntax.

Generated VBA bridge module for VBAPL_Execute calls


Compiled scripts use Unicode (UTF-16) strings internally, consistent with modern VBA. String comparisons default to binary comparison unless Option Compare Text is specified.

On Error GoTo and On Error Resume Next work as expected. The Err object provides Number and Description properties. However, Err.Raise with custom error numbers should use values above 512 to avoid conflicts with built-in errors.

Module-level code (code outside any Sub or Function) is executed when the module is first loaded. This happens on the first call to any function in that module.

  • Integer is 16-bit signed (−32,768 to 32,767)
  • Long is 32-bit signed (−2,147,483,648 to 2,147,483,647)
  • LongLong is 64-bit signed
  • Double follows IEEE 754 double-precision
  • Arithmetic rounding uses the Round function (arithmetic rounding, not banker’s rounding)

VBA Padlock can protect projects for these Office applications:

ApplicationFile TypesNotes
Excel.xlsm, .xlsb, .xla, .xlamMost common use case
Word.docm, .dotmDocuments and templates
Access.accdb, .accdeDatabases
PowerPoint.pptm, .ppamPresentations and add-ins

All Office versions from Office 2016 through Office 2024 and Microsoft 365 desktop apps are supported and tested, in both 32-bit and 64-bit editions.

Protected VBA result in Excel


  1. Move sensitive logic into the compiled DLL. Business rules, pricing algorithms, license checks, and proprietary calculations should all be in compiled scripts — that’s where they are protected.

  2. Use Application for Office interaction. Access worksheets, documents, ranges, and databases through the Application object inside compiled scripts rather than passing data back and forth unnecessarily.

  3. Test with the Test Runner. Use VBA Padlock’s built-in Test Runner to validate your compiled scripts before publishing.

  4. Use Option Explicit. Declare all variables explicitly to catch typos and type mismatches at compile time.

  5. Keep modules focused. Split your code into multiple .bas modules by responsibility. This improves readability and compilation diagnostics.

  6. Validate frequently with compilation + test run. Catch compatibility issues early in the build cycle.

Test Runner dialog to validate compiled scripts