agentleFS
90le90le/microsoft-excel-bi-agent/skills/excel-vba-workbook-engineering/SKILL.md

excel-vba-workbook-engineering

Skill2 starsChanged 5 months agoMITView on GitHub

Use when creating, modifying, or debugging .xlsx/.xlsm/.xlsb/.xls workbooks, VBA modules, macros, buttons, formulas, links, Power Query, or Excel COM/OpenXML automation.

The file

Show its rules and text

We split this skill into the rules it gives an agent

29 rules. About 0 are common, 10 are distinctive, and 19 are very specific to this project.

  • ≈0

    Common · estimate

    Many files like this have a rule of this kind.

  • ≈10

    Distinctive · estimate

    This author's own choices. Worth a look.

  • 19

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Distinctive:

    Treat Excel/VBA work as a binary-artifact engineering task.

    line 10
  2. Very specific:

    Windows desktop Excel available: Use Excel COM automation for the highest-fidelity workflow.

    line 14
  3. Very specific:

    Workbook without VBA: Prefer structured workbook tools or Python/JS libraries for .xlsx analysis, formula inspection, formatting, and data …

    line 16
  4. Very specific:

    Workbook depends on Excel-only features: Use live Excel for Solver, Power Query refresh, cube formulas, data model, macro buttons, chart …

    line 18
  5. Distinctive:

    If macros exist, export VBA components to a source folder before changing anything.

    line 35
  6. Very specific:

    Use scripts/inspect_workbook.ps1 or scripts/invoke_excel_com.sh inspect when Windows Excel is installed.

    line 36
  7. Very specific:

    Use scripts/inspect_openxml.py when running on Linux/macOS or when Excel is unavailable.

    line 37
  8. Distinctive:

    Keep user-facing sheets clean.

    line 42
  9. Very specific:

    Use .xlsm for macro-enabled deliverables.

    line 47
  10. Very specific:

    Keep VBA in exported .bas, .cls, or .frm files under a source folder.

    line 48
  11. Very specific:

    Use Option Explicit, clear public macro entry points, and late binding when references may be missing on another machine.

    line 49
  12. Very specific:

    Do not paste exported Attribute VB_Name = "..." lines directly into the VBE code pane.

    line 50
  13. Very specific:

    Prefer Form Control buttons or shapes with .OnAction = "MacroName" for simple workbooks.

    line 54
  14. Very specific:

    Ensure the target macro is Public Sub MacroName() in a standard module.

    line 55
  15. Very specific:

    When a deliverable depends on buttons, use the package-level tools/build_vba_button_binding_report.py with workbook inventory JSON and …

    line 56
  16. Distinctive:

    Avoid ActiveX controls unless the workbook already uses them or the user requires them.

    line 57
  17. Distinctive:

    Verify key output cells, formula errors, constraints, totals, and formatting.

    line 62
  18. Very specific:

    Use package-level tools/build_workbook_controls_report.py with OpenXML inspection JSON to review hidden/very hidden sheets, workbook …

    line 64
  19. Very specific:

    Use package-level tools/build_external_dependency_report.py with OpenXML inspection JSON before static or client handoff to flag workbook …

    line 65
  20. Distinctive:

    Check that hidden sheets, links, queries, and buttons are in the intended final state.

    line 66
  21. Distinctive:

    If working on Linux/macOS, state which validations were structural only and which still require Excel on Windows or Mac.

    line 68
  22. Distinctive:

    Use this source layout for nontrivial VBA work:

    line 78
  23. Very specific:

    Use scripts/export_vba.ps1 to export modules from an existing workbook.

    line 93
  24. Very specific:

    Start hidden Excel instances with Visible = $false and DisplayAlerts = $false.

    line 97
  25. Very specific:

    Always close workbooks and quit the COM Excel instance in finally.

    line 98
  26. Very specific:

    Do not kill all EXCEL.EXE processes.

    line 100
  27. Distinctive:

    Do not use destructive shell operations to move/delete workbook folders without verifying resolved paths.

    line 101
  28. Very specific:

    Prefer ASCII VBA module source when possible.

    line 106
  29. Distinctive:

    If Chinese literals are necessary, import and reopen the workbook to verify they survived.

    line 107

≈ “Common” is an estimate: at least 1 in 5 of the 213,897 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
SKILL.md

Excel VBA Workbook Engineering

Core Rule

Treat Excel/VBA work as a binary-artifact engineering task. Inspect the workbook first, edit a copy unless the user explicitly asks otherwise, keep VBA source diffable outside the workbook, then verify by reopening the workbook and running the relevant macros or formula checks.

Decision Path

  1. Windows desktop Excel available: Use Excel COM automation for the highest-fidelity workflow. From PowerShell call the .ps1 scripts directly. From Git Bash call scripts/invoke_excel_com.sh, which converts paths and invokes PowerShell.
  2. Linux/macOS or no Excel COM: Use OpenXML inspection and workbook libraries for .xlsx/.xlsm structure, formulas, styles, and data. Use scripts/inspect_openxml.py for a cross-platform JSON inventory. Do not claim that VBA can be compiled, buttons can be fully validated, Solver can run, or Power Query/data model can refresh without Excel.
  3. Workbook without VBA: Prefer structured workbook tools or Python/JS libraries for .xlsx analysis, formula inspection, formatting, and data extraction.
  4. Workbook with VBA or buttons: Export VBA components before editing when Excel COM is available. On Linux/macOS, preserve vbaProject.bin when editing .xlsm, but route final VBA import/compile/run validation to Windows Excel unless the user explicitly accepts manual validation.
  5. Workbook depends on Excel-only features: Use live Excel for Solver, Power Query refresh, cube formulas, data model, macro buttons, chart objects, ActiveX/Form controls, hidden/very hidden sheets, and legacy .xls.
  6. VBA project access is blocked: Tell the user that Excel's "Trust access to the VBA project object model" setting is required for automated export/import. Continue with manual instructions or workbook-level non-VBA edits if possible.

Platform Matrix

EnvironmentBest pathCan inspectCan edit workbookCan import/export VBACan compile/run VBA
Windows PowerShell + desktop ExcelExcel COM scriptsyesyesyesyes
Windows Git Bash + desktop Excelinvoke_excel_com.sh wrapperyesyesyesyes
Linux/macOS without ExcelOpenXML/Python/library pathpartialyes for .xlsx/some .xlsm editsno automated VBE export/importno
Linux/macOS with LibreOfficeLibreOffice/library pathpartialpartialno VBE-compatible import/exportno reliable Excel VBA validation

Required Workflow

  1. Inventory
    • Record the input workbook path, file type, and whether it contains macros.
    • List sheets, visible state, used ranges, formulas, names, shapes/buttons with OnAction, links, queries, and connections.
    • If macros exist, export VBA components to a source folder before changing anything.
    • Use scripts/inspect_workbook.ps1 or scripts/invoke_excel_com.sh inspect when Windows Excel is installed.
    • Use scripts/inspect_openxml.py when running on Linux/macOS or when Excel is unavailable.
  2. Plan the workbook shape
    • Decide which sheets are user-facing, calculation/support, hidden, or deleted.
    • Decide which cells are inputs, formulas, outputs, and diagnostics.
    • Keep user-facing sheets clean; hide support sheets only after validation.
    • Preserve existing visual conventions unless the user asks for redesign.
  3. Edit safely
    • Work on a copy by default. Never overwrite the only source workbook.
    • Use .xlsm for macro-enabled deliverables. Saving as .xlsx strips VBA.
    • Keep VBA in exported .bas, .cls, or .frm files under a source folder.
    • Use Option Explicit, clear public macro entry points, and late binding when references may be missing on another machine.
    • Do not paste exported Attribute VB_Name = "..." lines directly into the VBE code pane; those lines are valid in exported files, not manual paste text.
  4. Bind UI
    • Prefer Form Control buttons or shapes with .OnAction = "MacroName" for simple workbooks.
    • Ensure the target macro is Public Sub MacroName() in a standard module.
    • When a deliverable depends on buttons, use the package-level tools/build_vba_button_binding_report.py with workbook inventory JSON and lint_vba_source.py JSON to statically catch stale or missing OnAction macros before handoff.
    • Avoid ActiveX controls unless the workbook already uses them or the user requires them.
  5. Validate
    • Reopen the saved copy in Excel.
    • Compile VBA or run at least one representative macro.
    • Verify key output cells, formula errors, constraints, totals, and formatting.
    • For workbook deliverables with formulas, use package-level tools/build_formula_quality_report.py with OpenXML inspection JSON to flag cached formula errors, #REF!, local path references, volatile functions, and dynamic references before final handoff.
    • Use package-level tools/build_workbook_controls_report.py with OpenXML inspection JSON to review hidden/very hidden sheets, workbook protection, sheet protection, filters, frozen panes, and data validation rules before handoff.
    • Use package-level tools/build_external_dependency_report.py with OpenXML inspection JSON before static or client handoff to flag workbook connections, external links, external formulas, defined names, mashup/model markers, and credential-like connection string indicators without printing connection secrets.
    • Check that hidden sheets, links, queries, and buttons are in the intended final state.
    • Save a short validation note or test output when the workbook is a deliverable.
    • If working on Linux/macOS, state which validations were structural only and which still require Excel on Windows or Mac.
    • For package maintenance, the full release gate creates a temporary .xlsx workbook and validates scripts/inspect_workbook.ps1 against live Excel COM inventory fields: worksheet, formula count, workbook name, button shape, OnAction, and named range.
    • The full release gate also imports a temporary VBA module into a .xlsm, runs the imported macro, and exports the module back out to prove the live import/run/export path. The structural release gate intentionally skips these Excel runtime fixtures.
    • The release gate runs a static formula quality fixture so cached errors, #REF!, local paths, volatile functions, and dynamic references are covered without customer workbooks.
    • The release gate runs a static workbook controls fixture so hidden/very hidden sheets, workbook/sheet protection, filters, frozen panes, and data validation are covered without customer workbooks.
    • The release gate runs a static external dependency fixture so workbook connections, link parts, external formulas/names, mashup markers, and redacted credential-like connection string indicators are covered without customer workbooks.
    • The release gate also cross-checks generic button OnAction values against public VBA source entries so static button-to-macro binding drift is covered in both full and structural profiles.

VBA Source Discipline

Use this source layout for nontrivial VBA work:

project/
  deliverables/
    workbook_name.xlsm
  src/
    vba/
      modMain.bas
      modHelpers.bas
      ThisWorkbook.cls
  docs/
    validation.md

Use scripts/export_vba.ps1 to export modules from an existing workbook. Use scripts/import_vba.ps1 to import standard/class/form modules into a workbook copy. From Git Bash, use scripts/invoke_excel_com.sh export and scripts/invoke_excel_com.sh import. Read references/vba-patterns.md before writing or replacing VBA.

Excel COM Safety

  • Start hidden Excel instances with Visible = $false and DisplayAlerts = $false.
  • Always close workbooks and quit the COM Excel instance in finally.
  • Release COM objects where practical.
  • Do not kill all EXCEL.EXE processes. The user may have visible workbooks open. Only stop a process you created and can identify.
  • Do not use destructive shell operations to move/delete workbook folders without verifying resolved paths.

Encoding And Localization

  • VBA exported by the VBE is not a reliable UTF-8 interchange format on every Windows machine.
  • Prefer ASCII VBA module source when possible. For Chinese sheet names or labels, either reference existing worksheet objects, use values read from the workbook, or build literals with ChrW$.
  • If Chinese literals are necessary, import and reopen the workbook to verify they survived.
  • In terminal validation, avoid relying only on displayed Chinese text because console encoding may garble it. Verify through counts, formulas, cell addresses, and numeric values too.

References

Load only the reference needed for the task:

  • references/workflow.md: detailed workbook/VBA workflow, validation checklist, and troubleshooting.
  • references/vba-patterns.md: VBA coding patterns, macro button binding, Solver/automation notes, and common compile/runtime fixes.

Scripts

  • scripts/inspect_workbook.ps1 -WorkbookPath <path> [-OutJson <path>] creates a JSON inventory through Excel COM.
  • scripts/invoke_excel_com.sh inspect|export|import ... runs the Excel COM scripts from Git Bash/MSYS/Cygwin on Windows.
  • scripts/inspect_openxml.py <workbook> [--out-json <path>] creates a cross-platform OpenXML inventory for .xlsx/.xlsm without Excel.
  • scripts/export_vba.ps1 -WorkbookPath <path> -OutDir <folder> exports VBA components for review/editing.
  • scripts/import_vba.ps1 -WorkbookPath <path> -SourceDir <folder> -OutputWorkbookPath <path> copies a workbook and imports VBA modules from a source folder.
  • scripts/lint_vba_source.py <source-dir> [--strict-option-explicit] [--out-json <path>] statically checks exported or drafted .bas, .cls, and .frm files for parseable procedure blocks, duplicate public standard-module entry points, and missing Option Explicit before import.

These scripts are helpers, not substitutes for judgment. Read or patch them when a workbook has special requirements.

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.