excel-vba-modifier
Excel VBA Modifier Skill
Safe VBA code modification with xlwings
Overview
Automates VBA code modifications while ensuring safety:
- Verify Trust Center allows programmatic VBA access
- Read VBA module code from .xlsm files
- Write/modify VBA module code safely
- Run test macros to validate changes
- Automatic backup before modifications
When to Use
- Modifying VBA code: Safe xlwings-based editing
- Testing macro changes: Run macros to validate
- Debugging VBA: Read module code without manual editing
- Batch updates: Apply changes to multiple macros
- Following safety rules: Automatic backup and validation
Usage
# Check Trust Center permissions
conda run -n excel python script/modify_vba.py check-trust perturb_inform.xlsm
# Read a VBA module
conda run -n excel python script/modify_vba.py read perturb_inform.xlsm Module2
# Write/modify a VBA module (from file)
conda run -n excel python script/modify_vba.py write perturb_inform.xlsm Module2 new_code.vba
# Run a macro to test
conda run -n excel python script/modify_vba.py run perturb_inform.xlsm BuildMetaSummary
Features
Trust Center Checking
conda run -n excel python script/modify_vba.py check-trust file.xlsm
Output:
✓ Trust Center check passed
✓ VBA project access allowed
Reading VBA Code
conda run -n excel python script/modify_vba.py read file.xlsm Module2
Outputs module code to console (can redirect to file).
Writing VBA Code
# Write from file
conda run -n excel python script/modify_vba.py write file.xlsm Module2 new_code.vba
# Automatically creates backup first
# Then replaces module with new code
Running Macros
# Test macro after modification
conda run -n excel python script/modify_vba.py run file.xlsm BuildMetaSummary
# With arguments (if applicable)
conda run -n excel python script/modify_vba.py run file.xlsm Sub1 arg1 arg2
Safety Features
✓ Automatic backup before modifications ✓ Trust Center validation ✓ Test macro execution ✓ Error handling and rollback ✓ Windows only (COM access)
Integration with Other Skills
- excel-backup-manager: Auto-backup before writes
- excel-inspector: Understand VBA structure
- excel-na-utils: Helper functions for VBA code
Requirements
- OS: Windows only (xlwings COM access)
- Package: xlwings
- Trust Center: Must allow programmatic VBA access
- Excel: Installed and configured
Error Handling
| Error | Solution |
|---|---|
| Trust Center blocked | Enable in Excel: File > Options > Trust Center |
| Module not found | Use excel-inspector to list modules |
| Write failed | Check file isn't open in Excel |
| Macro failed | Check syntax in new VBA code |
Workflow
User request
↓
Check Trust Center
↓
Create backup (via excel-backup-manager)
↓
Read current module
↓
Write new module
↓
Run test macro
↓
Report success/failure
Files
vba_modifier.py: Core VBA modification logictrust_center_checker.py: Trust Center validation- CLI:
script/modify_vba.py
More from rukkha1024/elderly-balance-assessment
excel-backup-manager
Create, manage, and restore Excel file backups with automatic timestamps. Use before modifying Excel files to ensure data safety and enable rollback if needed.
12excel-inspector
Inspect Excel file structure (sheets, data types, VBA code) to help AI understand the workbook before writing code. Use when you need to understand an Excel file's schema, analyze data structure, or extract VBA code for modification.
9playwright-excel
Integrate Excel (.xlsx) data into Playwright codegen scripts by replacing hardcoded values with config-driven lookups, loading data with polars, and validating every step with Playwright MCP (start MCP from the repo if not running). Use for Playwright automation updates that require Excel-backed data, config.yaml centralization, or MCP validation/reporting.
9excel-na-utils
Helper functions for NA/missing value handling in Excel data. Provides Python and VBA implementations following CLAUDE.md NA handling guidelines.
8