Skip to content

Script Libraries & Constants

VBA Padlock ships with a set of ready-to-use script libraries: .bas modules containing thousands of Office VBA constants and utility functions that you can add to any project. These libraries let you use named constants like xlCenter, wdAlignParagraphLeft, or msoShapeRectangle directly in your compiled scripts, without needing a type library reference.

Excel Constants

~2,300 xl* and rgb* constants for full Excel automation.

Word Constants

~3,700 wd* constants for document formatting and manipulation.

PowerPoint Constants

~1,500 pp* constants for slides, transitions, and effects.

Access Constants

~1,200 ac* constants for forms, reports, and data operations.

Office Shared

~2,850 mso* constants for shapes, fills, and shared UI elements.

MSForms (UserForms)

~120 fm* constants for UserForm controls: mouse pointers, borders, scrollbars, list styles, and more.

Utility Libraries

Error handling and Financial functions ready for your business logic.


Adding Libraries to Your Project: the References Dialog

Section titled “Adding Libraries to Your Project: the References Dialog”

The References button (Protect tab → Project group) is the recommended way to use these libraries:

  1. Open the References dialog

    Click References in the Protect tab. The dialog lists every library as a checkbox tree, with a documentation preview for the selected module.

  2. Tick the modules you need

    Your host’s constants are pre-selected automatically (e.g. ExcelConstants + OfficeConstants for an Excel project). Tick extras like MSFormsConstants or Financial as needed.

  3. Click OK

    Checked modules compile into your DLL on every build; their constants and functions resolve in all your modules, no per-module directive required.

See the References dialog reference for details.


Section titled “Legacy: the References Directive and Templates Gallery”

Projects created with earlier versions may include library modules directly (via the Templates button) and reference them per module with a References directive at the very top of the file:

References ExcelConstants

Using the References directive to import WordConstants

  • The References directive must appear before any Option statement or code (it is also accepted in the declarations region after Attribute headers).
  • It uses the module name (as shown in the Project Explorer), not the file name.
  • You can reference multiple modules by adding several References lines.

This syntax still compiles, but for new projects prefer the References dialog; it keeps the libraries out of your module list and the selection in one place.


Explore the constants available for each Microsoft Office application.

Contains ~2,300 constants for automating Microsoft Excel. Covers the most commonly used xl* enumerations plus 150+ named RGB colors.

Excel code example

Key Categories:

CategoryExamplesCount
AlignmentxlCenter, xlLeft, xlRight20+
BordersxlContinuous, xlDash, xlDot15+
ChartsxlColumnClustered, xlLine, xlPie40+
ColorsrgbRed, rgbBlue, rgbCornflowerBlue150+
FormatsxlOpenXMLWorkbook, xlCSV, xlAddIn40+

Example:

References ExcelConstants
Function FormatReport()
Dim WS
Set WS = Application.ActiveSheet
WS.Range("A1:D1").HorizontalAlignment = xlCenter
WS.Range("A1:D10").Borders.LineStyle = xlContinuous
WS.Range("A1:D1").Interior.Color = rgbSteelBlue
FormatReport = "Done"
End Function

Helper modules for common programming tasks.

Provides 6 helper functions for structured error handling inside compiled scripts.

FunctionSignatureDescription
GetErrorInfoGetErrorInfo()Returns formatted string with Error details
FormatErrorFormatError(Num, [Desc])Returns formatted error message
HasErrorHasError()True if Err.Number <> 0
ClearErrorClearError()Clears the Err object

Example:

References ErrorHandler
Function SafeDivide(A, B)
On Error Resume Next
SafeDivide = A / B
If HasError() Then
SafeDivide = "Error: " & GetErrorInfo()
ClearError
End If
End Function