vba-extractor

majiayu000's avatarfrom majiayu000

Extract VBA/macro code from Microsoft Office files (.xlsm, .xlsb, .docm, .pptm). This skill should be used when users want to read, view, or extract VBA macros from Excel workbooks or other Office documents containing embedded VBA projects.

⭐5stars🔀1forks📁View on GitHub🕐Updated Jan 11, 2026

When & Why to Use This Skill

This Claude skill provides a streamlined way to extract and view VBA macro source code from various Microsoft Office formats, including .xlsm, .xlsb, .docm, and .pptm. By leveraging the specialized oletools library, it automates the decompression of binary VBA projects, allowing users to audit, document, or migrate legacy Office automation logic without needing to open the files in their native applications.

Use Cases

  • Security Auditing: Safely inspect macro-enabled Office documents for potentially malicious code or unauthorized scripts without executing the file.
  • Legacy System Migration: Extract complex VBA logic from old Excel or Word files to facilitate porting functionality to modern platforms like Python or web-based tools.
  • Code Recovery: Retrieve lost or undocumented source code from legacy .xls or .doc files to maintain and update critical business workflows.
  • Automated Documentation: Generate technical summaries and documentation for complex Excel-based tools by analyzing the underlying VBA modules and logic.
namevba-extractor
descriptionExtract VBA/macro code from Microsoft Office files (.xlsm, .xlsb, .docm, .pptm). This skill should be used when users want to read, view, or extract VBA macros from Excel workbooks or other Office documents containing embedded VBA projects.

VBA Extractor

Extract and display VBA macro code from Microsoft Office files.

Overview

This skill enables extraction of VBA (Visual Basic for Applications) code from Office files with embedded macros. VBA code is stored in a compressed binary format inside Office files and requires specialized tools to extract.

Supported File Types

  • .xlsm - Excel Macro-Enabled Workbook
  • .xlsb - Excel Binary Workbook
  • .docm - Word Macro-Enabled Document
  • .pptm - PowerPoint Macro-Enabled Presentation
  • .xls - Legacy Excel files (97-2003)
  • .doc - Legacy Word files (97-2003)

Workflow

Step 1: Verify Python and oletools

The extraction requires Python with the oletools package:

python --version
pip install oletools

If oletools is not installed, install it first.

Step 2: Extract VBA Code

Run olevba with the -c flag to extract only the code (no analysis):

python -m oletools.olevba "<path-to-file>" -c > vba_code.txt

The -c flag outputs only the VBA source code without the security analysis.

Step 3: Read the Output

Read the generated vba_code.txt file to view the extracted VBA code.

Common Issues

Windows Encoding Errors

On Windows, the console may fail with Unicode encoding errors. To avoid this, always redirect output to a file:

python -m oletools.olevba "file.xlsm" -c > output.txt 2>nul

No VBA Project Found

If no VBA is found, the file may not contain macros or may be a different format (e.g., .xlsx instead of .xlsm).

JavaScript libraries like cfb, xlsx, and ole-doc can read the VBA project structure but cannot reliably decompress the VBA source code. The Microsoft VBA compression algorithm is proprietary and these libraries lack proper decompression support.

What works: Python's oletools library What doesn't work reliably: JavaScript-based extraction

Output Format

The extracted output includes:

  • Module names (e.g., CropBoxes.bas, Sheet1.cls)
  • Full VBA source code for each module
  • Separation markers between modules

Example output structure:

VBA MACRO ModuleName.bas
in file: xl/vbaProject.bin - OLE stream: 'VBA/ModuleName'
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Sub MySub()
    ' VBA code here
End Sub