Version-control Excel macro code in git by extracting all VBA modules to plain text files with a single command.
Generate or modify Excel macros from a Python script as part of a CI/CD pipeline on a server with no Excel.
Inspect and diff VBA code across two versions of a workbook to see exactly what macro logic changed.
Create a brand-new macro-enabled Excel workbook from scratch in Python without opening Excel at all.
Saving changes to a workbook removes any existing digital signature on the VBA project.
Excel files can contain macros, which are small programs written in a language called VBA (Visual Basic for Applications). These macros automate tasks inside spreadsheets. pyOpenVBA is a Python library for reading those macros out of Excel files and writing changes back in, without needing Excel installed on your computer. The key distinction from similar tools is the write capability. Several other Python libraries can extract VBA code for inspection, but they stop there. pyOpenVBA is designed for the round-trip: pull the code out, edit it, push it back in, and have the resulting file open in Excel without any error or repair prompt. This makes it useful for version-controlling macro code in git like any other source file, generating or modifying macros from a script, running automation on a server where Excel is not present, and comparing two workbooks to see what changed. The core API is three methods: list the modules in a workbook, read a module's code as text, and replace a module's code. Beyond that, you can add new modules, rename existing ones, delete them, and create a fresh macro-enabled workbook from scratch without opening Excel at all. The command-line interface lets you pull all modules from a workbook into a folder of plain text files, edit them in any editor, and push them back. The library handles four Excel file formats: xlsm (macro-enabled workbook), xlsb (binary workbook), xlam (add-in), and the older xls format from before 2007. It works on Windows, macOS, and Linux, and requires no external dependencies beyond Python 3.10 or later. There are some deliberate limits. The library works on the source code of macros, not on the visual layout of dialog forms embedded in a workbook. It does not decrypt password-protected VBA projects (though it can still write to them if you explicitly allow it), and any digital signature on the macros is removed when changes are saved.
← williamsmithedward on gitmyhub — every repo by this author, as a profile.
Verify against the repo before relying on details.