explaingit

williamsmithedward/pyopenvba

12PythonAudience · developerComplexity · 2/5Setup · easy

TLDR

A Python library for reading, editing, and writing back VBA macros in Excel files without needing Excel installed, enabling version control and scripted automation of Excel macro code.

Mindmap

mindmap
  root((pyOpenVBA))
    What it does
      Read VBA modules
      Edit macro code
      Write back to Excel
      Create new workbooks
    Supported formats
      xlsm
      xlsb
      xlam
      xls
    Use cases
      Git version control
      CI macro automation
      Server-side editing
      Diff two workbooks
    Platforms
      Windows
      macOS
      Linux
Click or tap to explore — scroll the page freely

Code map

Detail Auto

An interactive map of this repo's files and how they connect — its source is parsed live in your browser. Click Visualize to build it.

filefunction / class

Things people build with this

USE CASE 1

Version-control Excel macro code in git by extracting all VBA modules to plain text files with a single command.

USE CASE 2

Generate or modify Excel macros from a Python script as part of a CI/CD pipeline on a server with no Excel.

USE CASE 3

Inspect and diff VBA code across two versions of a workbook to see exactly what macro logic changed.

USE CASE 4

Create a brand-new macro-enabled Excel workbook from scratch in Python without opening Excel at all.

Tech stack

Pythonxlsmxlsbxlamxls

Getting it running

Difficulty · easy Time to first run · 5min

Saving changes to a workbook removes any existing digital signature on the VBA project.

In plain English

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.

Copy-paste prompts

Prompt 1
Using pyOpenVBA, write a Python script that extracts all VBA modules from an xlsm file into a folder of plain text files so I can commit them to a git repository.
Prompt 2
I want to replace the contents of a specific VBA module in an Excel file using pyOpenVBA. Show me the three steps: list modules, read the target, and write the updated code back.
Prompt 3
Help me set up a GitHub Actions workflow that uses pyOpenVBA to push updated macro code from a macros/ folder back into an xlsm file on every commit.
Prompt 4
Using pyOpenVBA, write a script that creates a new macro-enabled xlsm workbook from scratch, adds a VBA module with a Hello World sub, and saves the file.
Open on GitHub → Explain another repo

← williamsmithedward on gitmyhub — every repo by this author, as a profile.

Verify against the repo before relying on details.