pyVBAanalysis
Static analysis for Office VBA. It reads your macros and reports likely bugs and the errors the VBA compiler would catch, without opening Office or running any code.
Point it at an Excel workbook, a Word document, a PowerPoint deck, an Access database, or a set of exported module files, and it returns the problems it finds, each with the exact line and a plain explanation. Each file is measured against its own host's object model, so Word code is never judged by Excel's surface.
What it checks
It looks for more than a hundred kinds of problem, including:
- Type errors, such as assigning a string to a
Longor passing the wrong type to a procedure. - Undeclared variables and calls to procedures or members that do not exist.
- Code the VBA compiler rejects: duplicate declarations, malformed statements, or a
Declarethat lacksPtrSafeon 64-bit Office. - Likely run-time failures, such as dividing by a constant zero or a type mismatch from a bad conversion.
It only reports a problem when it can prove one, and stays quiet otherwise, so the output does not bury you in false alarms.
Install
pip install pyvbaanalysis
Python 3.10 or later. Nothing else to set up.
Use it from Python
Analyze a workbook:
from pyvbaanalysis import analyze_office_file
for module, problems in analyze_office_file("Budget.xlsm").items():
for p in problems:
print(module, p.severity.value, p.code, p.message)
Analyze a single module's source:
from pyvbaanalysis import analyze_module
source = "Sub Test()\n Dim n As Long\n n = \"oops\"\nEnd Sub\n"
for p in analyze_module(source):
print(p.code, p.message)
Each result has a code, a message, a severity (error, warning, or
information), and a span giving the character offsets in the source.
Analyze several exported files together, so references between them resolve:
from pyvbaanalysis import analyze_loose_files
analyze_loose_files(["Module1.bas", "Sheet1.cls", "UserForm1.frm"])
Use it from the command line
pyvbaanalysis Budget.xlsm
pyvbaanalysis ./exported_modules --format json
pyvbaanalysis Budget.xlsm --only Sheet1
A path can be a workbook, a folder of exported .bas / .cls / .frm files, or a
single file. The command exits 1 when it finds problems and 0 when the code is
clean, so it drops into a CI check.
Scope
This analyzes the VBA inside Office files. It does not run macros and does not need Office installed.
Each file is measured against its own host's object model, so a Word document is never judged by Excel's surface. Readable containers: Excel (.xlsm, .xlsb, .xlam, .xls), Word (.docm, .dotm, .doc), PowerPoint (.pptm, .potm) and Access (.accdb, .mdb, read-only). Legacy .ppt is not readable yet, because its VBA project sits in a compressed record the reader does not open.
Documentation
License
MIT. See LICENSE.
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file pyvbaanalysis-2.0.0.tar.gz.
File metadata
- Download URL: pyvbaanalysis-2.0.0.tar.gz
- Upload date:
- Size: 1.0 MB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via:
twine/7.0.0 CPython/3.13.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
8cf9007a6c87c22f6e9b0150fc7ac48efeeec22e67c4c53fd31796b8b6008334
|
|
| MD5 |
ecbfdc60416342656d55f88b94bc11d3
|
|
| BLAKE2b-256 |
2473c67727ffa6fe2c813dd24ca70bd9ed78b57c54078218d0b8ba69c5120b52
|
Provenance
The following attestation bundles were made for pyvbaanalysis-2.0.0.tar.gz:
Publisher:
publish.yml on WilliamSmithEdward/pyVBAanalysis
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
pyvbaanalysis-2.0.0.tar.gz -
Subject digest:
8cf9007a6c87c22f6e9b0150fc7ac48efeeec22e67c4c53fd31796b8b6008334 - Sigstore transparency entry: 2513417772
- Sigstore integration time:
-
Permalink:
WilliamSmithEdward/pyVBAanalysis@d5ea76b5787b9b7aeada3bc67fd4c4fa6d59942a -
Branch / Tag:
refs/tags/v2.0.0 - Owner: https://github.com/WilliamSmithEdward
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@d5ea76b5787b9b7aeada3bc67fd4c4fa6d59942a -
Trigger Event:
release
-
Statement type:
File details
Details for the file pyvbaanalysis-2.0.0-py3-none-any.whl.
File metadata
- Download URL: pyvbaanalysis-2.0.0-py3-none-any.whl
- Upload date:
- Size: 944.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via:
twine/7.0.0 CPython/3.13.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
feabc6b5594cbf76388c31648d3540c46d619818e1762ba26d3e62be339cf430
|
|
| MD5 |
7861c876f213c7ce7224355f41293d43
|
|
| BLAKE2b-256 |
3b3efa961eb3e692815c0c14f594360ddc30ab73c48738660246ac9e6f76dc63
|
Provenance
The following attestation bundles were made for pyvbaanalysis-2.0.0-py3-none-any.whl:
Publisher:
publish.yml on WilliamSmithEdward/pyVBAanalysis
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
pyvbaanalysis-2.0.0-py3-none-any.whl -
Subject digest:
feabc6b5594cbf76388c31648d3540c46d619818e1762ba26d3e62be339cf430 - Sigstore transparency entry: 2513418027
- Sigstore integration time:
-
Permalink:
WilliamSmithEdward/pyVBAanalysis@d5ea76b5787b9b7aeada3bc67fd4c4fa6d59942a -
Branch / Tag:
refs/tags/v2.0.0 - Owner: https://github.com/WilliamSmithEdward
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@d5ea76b5787b9b7aeada3bc67fd4c4fa6d59942a -
Trigger Event:
release
-
Statement type: