Skip to main content

Pure-Python static analysis for Excel VBA

Project description

pyVBAanalysis

Static analysis for Excel VBA. It reads your macros and reports likely bugs and the errors the VBA compiler would catch, without opening Excel or running any code.

Point it at a workbook or a set of exported module files, and it returns the problems it finds, each with the exact line and a plain explanation.

What it checks

It looks for more than a hundred kinds of problem, including:

  • Type errors, such as assigning a string to a Long or 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, a missing Option Explicit, malformed statements, or a Declare that lacks PtrSafe on 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_workbook

for module, problems in analyze_workbook("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 Excel VBA. It does not run macros and does not need Excel installed. Word and PowerPoint are not supported.

Documentation

License

MIT. See LICENSE.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pyvbaanalysis-1.1.1.tar.gz (562.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

pyvbaanalysis-1.1.1-py3-none-any.whl (509.1 kB view details)

Uploaded Python 3

File details

Details for the file pyvbaanalysis-1.1.1.tar.gz.

File metadata

  • Download URL: pyvbaanalysis-1.1.1.tar.gz
  • Upload date:
  • Size: 562.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for pyvbaanalysis-1.1.1.tar.gz
Algorithm Hash digest
SHA256 dfa10a6a01105a106e552bd879a1ad0faf384a29130236ae25aa5ae3ecc684a5
MD5 61faf5b716a2ddb7dcf2a4e874a5ae89
BLAKE2b-256 96309bab4788e1fef59f84f62858670893e1b3fb19e9a1de67270c053996e711

See more details on using hashes here.

Provenance

The following attestation bundles were made for pyvbaanalysis-1.1.1.tar.gz:

Publisher: publish.yml on WilliamSmithEdward/pyVBAanalysis

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file pyvbaanalysis-1.1.1-py3-none-any.whl.

File metadata

  • Download URL: pyvbaanalysis-1.1.1-py3-none-any.whl
  • Upload date:
  • Size: 509.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for pyvbaanalysis-1.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 62b535d74eed99c357810f4b9d907aace1cbe92f0d52a2d1059f8be1315978d6
MD5 592a2831c0c36b524e8ea81ae11e56ca
BLAKE2b-256 14bb530b1e4f85da8cc7d8ca4521fc84ea90f196b0d60074ce1b283811035a38

See more details on using hashes here.

Provenance

The following attestation bundles were made for pyvbaanalysis-1.1.1-py3-none-any.whl:

Publisher: publish.yml on WilliamSmithEdward/pyVBAanalysis

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page