
Excel Vba Modifier
- 33 installs
- Updated March 16, 2026
- rukkha1024/elderly-balance-assessment
Excel VBA Modifier is an agent skill that safely reads, writes, and runs Excel VBA modules on Windows using xlwings with Trust Center and backup gates.
About
Excel VBA Modifier is an agent skill for solo builders who maintain mission-critical Excel macros—assessment forms, ops dashboards, or research workbooks—and need programmatic edits without corrupting modules. It wraps xlwings to read VBA modules, replace code from .vba files, and execute test macros after Trust Center verification. The workflow enforces safety: confirm Excel trusts programmatic access, ensure the workbook is not open elsewhere, backup via excel-backup-manager, then write and run a validation macro such as BuildMetaSummary. It targets Windows hosts with a conda excel environment, matching clinical or operations teams that still ship logic inside .xlsm assets. Use it in Build when you extend or refactor VBA as part of a larger Python-assisted pipeline (for example elderly balance assessment spreadsheets). It is not a cross-platform Excel.js replacement; skip it if you only need CSV exports or Google Sheets.
- Trust Center validation before any VBA read or write via trust_center_checker
- Read, write, and run_macro flows backed by vba_modifier.py and modify_vba.py CLI
- Mandatory backup discipline with excel-backup-manager before writes
- Windows-only xlwings COM requirement with closed-workbook safety rules
- Conda-run CLI verbs: check-trust, read, write, run for agent-driven pipelines
Excel Vba Modifier by the numbers
- 33 all-time installs (skills.sh)
- Ranked #403 of 688 Office & Documents skills by installs in the Skillselion catalog
- Security screen: MEDIUM risk (skills.sh audit)
- Data as of Aug 5, 2026 (Skillselion catalog sync)
npx skills add https://github.com/rukkha1024/elderly-balance-assessment --skill excel-vba-modifierAdd your badge
Show developers this skill is listed on Skillselion. Paste this into your README.
| Installs | 33 |
|---|---|
| Security audit | 2 / 3 scanners passed |
| Last updated | March 16, 2026 |
| Repository | rukkha1024/elderly-balance-assessment ↗ |
What it does
Safely read, replace, and test VBA in Excel workbooks using xlwings with Trust Center checks and mandatory backups on Windows.
Who is it for?
Windows-based developers automating legacy Excel workbooks with Python and conda-managed xlwings.
Skip if: macOS/Linux-only workflows, greenfield web apps that should replace Excel, or edits without backup and Trust Center approval.
When should I use this skill?
You need to read, update, or test VBA in an Excel .xlsm on Windows with xlwings after Trust Center validation.
What you get
You get verified read/write macro cycles with backup-first discipline and a test macro run to confirm the module still executes.
- Updated VBA module content in target .xlsm
- Macro execution verification output
By the numbers
- Five core safety rules including backup-first and Windows-only COM
- CLI exposes check-trust, read, write, and run operations
Files
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 BuildMetaSummaryFeatures
Trust Center Checking
conda run -n excel python script/modify_vba.py check-trust file.xlsmOutput:
✓ Trust Center check passed
✓ VBA project access allowedReading VBA Code
conda run -n excel python script/modify_vba.py read file.xlsm Module2Outputs 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 codeRunning 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 arg2Safety 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/failureFiles
vba_modifier.py: Core VBA modification logictrust_center_checker.py: Trust Center validation- CLI:
script/modify_vba.py
Excel VBA Modifier
xlwings를 사용한 안전한 VBA 코드 수정.
주요 기능
- Trust Center 검증: VBA 접근 권한 확인
- 모듈 읽기: VBA 모듈 코드 추출
- 모듈 쓰기: VBA 코드 수정/교체
- 매크로 실행: 테스트 매크로 실행
- 자동 백업: 수정 전 자동 백업 (excel-backup-manager 연동)
사용법
Python에서
from vba_modifier import read_vba_module, write_vba_module, run_macro
# VBA 읽기
code = read_vba_module('perturb_inform.xlsm', 'Module2')
print(code)
# VBA 쓰기 (항상 백업 먼저!)
with open('new_code.vba', 'r') as f:
new_code = f.read()
write_vba_module('perturb_inform.xlsm', 'Module2', new_code)
# 매크로 실행
run_macro('perturb_inform.xlsm', 'BuildMetaSummary')CLI에서
# Trust Center 검증
conda run -n excel python script/modify_vba.py check-trust perturb_inform.xlsm
# 모듈 읽기
conda run -n excel python script/modify_vba.py read perturb_inform.xlsm Module2
# 모듈 쓰기 (백업 필수!)
conda run -n excel python script/modify_vba.py write perturb_inform.xlsm Module2 new_code.vba
# 매크로 실행
conda run -n excel python script/modify_vba.py run perturb_inform.xlsm BuildMetaSummary파일
| 파일 | 설명 |
|---|---|
SKILL.md | Skill 메타데이터 |
vba_modifier.py | VBA 읽기/쓰기 핵심 로직 |
trust_center_checker.py | Trust Center 검증 |
README.md | 이 파일 |
안전성 규칙
✓ 항상 백업 먼저: excel-backup-manager 사용 ✓ Trust Center 확인: 수정 전 권한 검증 ✓ 테스트 매크로 실행: 수정 후 검증 ✓ Windows 전용: xlwings COM 접근 필요 ✓ 파일 체크: 수정 중 파일 열려있으면 안됨
Trust Center 설정
Windows Excel에서 VBA 접근을 허용하려면:
1. Excel 실행 2. 파일 > 옵션 > 보안 센터 3. 보안 센터 설정 4. 매크로 설정 탭에서:
- ✓ 모든 매크로 사용 또는
- ✓ 알림을 표시하고 사용 안 함 매크로 사용
5. 신뢰할 수 있는 게시자 탭에서:
- ✓ VBA 프로젝트 개체 모델에 대한 신뢰할 수 있는 액세스 허용
6. 확인
워크플로우 예시
from backup_manager import create_backup, restore_backup
from vba_modifier import read_vba_module, write_vba_module, run_macro
from trust_center_checker import check_trust_center_windows
# 1. Trust Center 검증
allowed, msg, sol = check_trust_center_windows()
if not allowed:
raise RuntimeError(f"VBA access blocked: {msg}")
# 2. 백업 생성
backup = create_backup('perturb_inform.xlsm')
try:
# 3. 현재 코드 읽기
old_code = read_vba_module('perturb_inform.xlsm', 'Module2')
# 4. 새 코드 쓰기
with open('new_code.vba', 'r') as f:
new_code = f.read()
write_vba_module('perturb_inform.xlsm', 'Module2', new_code)
# 5. 테스트 매크로 실행
run_macro('perturb_inform.xlsm', 'BuildMetaSummary')
print("✓ VBA modification successful")
except Exception as e:
print(f"❌ Error: {e}")
# 6. 오류 시 복원
restore_backup(backup)
raise다른 Skills와의 연결
- excel-backup-manager: 수정 전 자동 백업
- excel-inspector: 모듈 구조 파악
- excel-na-utils: VBA 헬퍼 함수
필수 패키지
conda run -n excel pip install xlwings주의사항
⚠️ Windows 전용: macOS/Linux에서는 VBA 접근 불가 ⚠️ 파일 미접속: 수정 중 파일이 Excel에 열려있으면 안됨 ⚠️ 백업 필수: 항상 수정 전 백업 생성 ⚠️ 테스트 필수: 수정 후 매크로 실행 테스트 필수
"""
Excel Trust Center Checker
Validates that Excel Trust Center allows programmatic VBA access.
"""
import sys
def check_trust_center_windows():
"""
Check if Excel Trust Center allows VBA access on Windows.
Returns:
(bool, str, str): (allowed, message, solution)
"""
if sys.platform != 'win32':
return None, "Not Windows", "VBA access requires Windows OS"
try:
import xlwings as xw
except ImportError:
return None, "xlwings not installed", "Install with: conda run -n excel pip install xlwings"
try:
app = xw.App(visible=False)
try:
# Try to access VBA project
for book in app.books:
try:
vba = book.xl_workbook.VBProject
# If we can access VBProject, Trust Center is OK
return True, "VBA access allowed", None
except:
pass
return False, "Trust Center blocks VBA access", trust_center_solution()
finally:
app.quit()
except Exception as e:
return False, f"Excel access failed: {str(e)}", trust_center_solution()
def trust_center_solution():
"""Return instructions to enable Trust Center."""
return """
Solution: Enable VBA access in Excel Trust Center
1. Open Excel
2. File > Options > Trust Center > Trust Center Settings
3. Macro Settings: Select "Enable all macros"
OR
4. Macro Settings > Select "Disable all macros with notification"
(will show notification button to enable)
5. Trust Center tab > Check "Trust access to VBA project object model"
6. Click OK and restart Excel
"""
def display_result(allowed, message, solution):
"""Display check result."""
if allowed is True:
print("✓ Trust Center check PASSED")
print(f" {message}")
return 0
elif allowed is False:
print("✗ Trust Center check FAILED")
print(f" {message}")
if solution:
print(f"\n{solution}")
return 1
else:
print("? Trust Center check INCONCLUSIVE")
print(f" {message}")
if solution:
print(f" {solution}")
return 2
if __name__ == '__main__':
allowed, msg, sol = check_trust_center_windows()
exit_code = display_result(allowed, msg, sol)
sys.exit(exit_code)
"""
Excel VBA Modifier
Safely modify VBA modules in Excel files using xlwings.
"""
import sys
import subprocess
from pathlib import Path
def check_trust_center():
"""
Check if Trust Center allows VBA access.
Returns:
(bool, str): (success, message)
"""
if sys.platform != 'win32':
return False, "VBA access requires Windows"
try:
import xlwings as xw
# Try to access VBProject
app = xw.App(visible=False)
try:
# This will fail if Trust Center blocks it
app.books
return True, "Trust Center allows VBA access"
finally:
app.quit()
except ImportError:
return False, "xlwings not installed"
except Exception as e:
return False, f"Trust Center blocked: {str(e)}"
def read_vba_module(excel_file: str, module_name: str) -> str:
"""
Read VBA module code from Excel file.
Args:
excel_file: Path to .xlsm file
module_name: Name of VBA module (e.g., 'Module2', 'ThisWorkbook')
Returns:
VBA code as string
Example:
code = read_vba_module('file.xlsm', 'Module2')
print(code) # [VBA code...]
"""
if sys.platform != 'win32':
raise RuntimeError("VBA access requires Windows")
try:
import xlwings as xw
except ImportError:
raise ImportError("xlwings required: conda run -n excel pip install xlwings")
excel_path = Path(excel_file)
if not excel_path.exists():
raise FileNotFoundError(f"Excel file not found: {excel_file}")
app = xw.App(visible=False)
try:
wb = app.books.open(str(excel_path.absolute()))
try:
vba_project = wb.xl_workbook.VBProject
# Find module
for module in vba_project.VBComponents:
if module.Name == module_name:
code = module.CodeModule.Read()
return code
raise ValueError(f"Module not found: {module_name}")
finally:
wb.close()
finally:
app.quit()
def write_vba_module(excel_file: str, module_name: str, code: str) -> bool:
"""
Write/replace VBA module code in Excel file.
Args:
excel_file: Path to .xlsm file
module_name: Name of VBA module to replace
code: New VBA code
Returns:
bool: True if successful
Example:
with open('new_code.vba', 'r') as f:
new_code = f.read()
write_vba_module('file.xlsm', 'Module2', new_code)
"""
if sys.platform != 'win32':
raise RuntimeError("VBA access requires Windows")
try:
import xlwings as xw
except ImportError:
raise ImportError("xlwings required: conda run -n excel pip install xlwings")
excel_path = Path(excel_file)
if not excel_path.exists():
raise FileNotFoundError(f"Excel file not found: {excel_file}")
app = xw.App(visible=False)
try:
wb = app.books.open(str(excel_path.absolute()))
try:
vba_project = wb.xl_workbook.VBProject
# Find and replace module
for module in vba_project.VBComponents:
if module.Name == module_name:
code_module = module.CodeModule
# Clear and write new code
code_module.DeleteLines(1, code_module.CountOfLines)
code_module.AddFromString(code)
wb.save()
return True
raise ValueError(f"Module not found: {module_name}")
finally:
wb.close()
finally:
app.quit()
def run_macro(excel_file: str, macro_name: str, *args) -> bool:
"""
Run a VBA macro.
Args:
excel_file: Path to .xlsm file
macro_name: Macro name (e.g., 'BuildMetaSummary')
*args: Arguments to pass to macro (optional)
Returns:
bool: True if successful
Example:
run_macro('file.xlsm', 'BuildMetaSummary')
"""
if sys.platform != 'win32':
raise RuntimeError("Macro execution requires Windows")
try:
import xlwings as xw
except ImportError:
raise ImportError("xlwings required: conda run -n excel pip install xlwings")
excel_path = Path(excel_file)
if not excel_path.exists():
raise FileNotFoundError(f"Excel file not found: {excel_file}")
app = xw.App(visible=False)
try:
wb = app.books.open(str(excel_path.absolute()))
try:
macro = wb.macro(macro_name)
if args:
macro(*args)
else:
macro()
return True
finally:
wb.close()
finally:
app.quit()
if __name__ == '__main__':
# Test
import sys
if len(sys.argv) > 1:
# Test Trust Center
success, msg = check_trust_center()
print(f"Trust Center: {msg}")
Related skills
How it compares
Office integration skill with enforced backup—not ad-hoc copy-paste of VBA in chat.
FAQ
Who is excel-vba-modifier for?
Developers and analysts who own.xlsm tools on Windows and want agents to apply vetted VBA patches through xlwings and a CLI.
When should I use excel-vba-modifier?
During Build integrations work when you need to extract Module2, deploy new_code.vba, and run BuildMetaSummary after Trust Center check on a closed workbook.
Is excel-vba-modifier safe to install?
Review the Security Audits panel on this Prism page; the skill writes to workbooks and runs macros—only use on copies until backups pass and Trust Center is explicitly configured.