VBAlidator is a robust, platform-independent static analysis tool for VBA (Visual Basic for Applications). It allows you to simulate the "compilation" of VBA code exported from MS Office applications on any environment (Windows, Linux, or Mac), ensuring code integrity without needing to open the Office application itself.
- Static Analysis: Detects undefined variables, invalid member access, and type mismatches.
- Dynamic Object Model: Generate and load object models for any VBA host (Visio, Excel, Word, AutoCAD) using the integrated TLI-based generator.
- Deep Parsing: Comprehensive parser handling nested
Withblocks, multi-statement lines, and complex loops. - Conditional Compilation: Full support for
#If...#Elsedirectives to simulate different environments (e.g., Win64 vs Win32). - Form Support: Intelligent heuristics for
.frmfiles to handle implicit GUI controls andUserFormmembers. - CI/CD Ready: Returns exit codes and generates JSON reports for seamless integration into build pipelines.
-
Clone the repository:
git clone https://github.com/twobeass/VBAlidator.git cd VBAlidator -
Install the package:
pip install .This will install the dependencies and the
vbalidatorcommand-line tool.
To validate host-specific code (e.g., Visio.Shape), you first need a model of that host.
- Use
tools/VBA_Model_Exporter.basin your Office application to export references. - Run the generator:
python tools/generate_model.py.
If you have a vba_model.json in your current directory, it will be automatically used.
vbalidator ./path/to/vba_codeYou can also specify the model manually:
vbalidator ./path/to/vba_code --model /path/to/vba_model.jsonDetailed documentation is available in the docs/ folder:
- Usage Guide: CLI arguments, options, and advanced usage.
- Configuration: How to generate custom Object Models and how heuristics work.
- Architecture: Deep dive into the Lexer, Parser, and Analyzer.
vbalidator tests/samples/valid_codeTo see the tool in action against intentional errors, check the tests/demo folder:
vbalidator tests/demoThis project is licensed under the MIT License.