Introduction¶
A common approach for having AI modify Excel macros in DSH (DeepSeek Harness) involves unzipping the workbook, tampering with vbaProject.bin, or exporting modules as text and stitching them back together. Such paths easily become disconnected from Excel’s own compilation and saving semantics, and whether the changes can be accepted by Excel often requires manually opening the VBE once for confirmation.
dsh-vba-bridge takes a different route: it uses the COM and VBIDE interfaces of the local desktop Excel to list modules, read source code, write code, and export components. After saving, it reopens the workbook in the same Excel instance for SHA-256 verification. The macros are compiled and persisted to disk by Excel, rather than having the binary unpacked outside the package. Below is an introduction to the plugin’s positioning, tool capabilities, installation prerequisites, and typical usage.
What It Is¶
dsh-vba-bridge is a DSH Host plugin (maintainer: alexltr) that exposes the read and write capabilities of VBA projects as Harness-callable tools in a Windows + desktop Microsoft Excel environment. The target files are .xlsm, .xlsb, .xls, and .xlam; plain .xlsx files lack a VBA container and will be rejected.
The current plugin version is 0.1.1 under the MIT license. package.json requires Node ^22.19 || >=24 and DSH >=0.2.0-0 <0.3.0, and supports only win32.
Core Features¶
After installation, six tools are registered. Relative paths are resolved against the DSH session working directory, while absolute paths are used as-is.
| Tool | Purpose |
|---|---|
vba_doctor |
Recommended to run after installation: checks Python, pywin32, Excel COM, AccessVBOM, offline parser, and temp directory, with an optionally specified workbook |
vba_inspect |
Project name, protection status, all components (modules/worksheets/ThisWorkbook/forms), and references |
vba_read_module |
Reads a single module’s source code, including the code region of UserForms |
vba_write_module |
Replaces/appends/creates modules, saves in place, reopens for verification, and generates a .bak file |
vba_export_modules |
Exports all components: source code (.bas/.cls/.frm) or native .frm + .frx, and writes a _manifest.json |
vba_list_procedures |
Lists parameters and start/end line numbers for Sub/Function/Property, including form event handlers |
Write Semantics (vba_write_module)
mode=replace: Overwrites the module’s code region; hiddenVB_*attributes are preserved by Excel.mode=append: Reads the old code, concatenates the new code, and then rewrites it entirely.create=true: Creates a new standard module if it does not exist.- Every write first copies a backup named
originalname.YYYYmmdd-HHMMSS.bak.xlsm. After saving, it reopens the workbook in the same Excel instance to compare the source code SHA-256 and returnsverified: true/false.
Forms (UserForm)
A form’s code corresponds to its CodeModule; event procedures can be read and written like those in normal modules. Only the code region is modified—control layout, the properties page, and the .frx design data remain untouched. When exporting with mode=component, you get a .frm + .frx pair with the complete OleObjectBlob; a mode=code .frm contains only code and cannot be directly re-imported.
Export
mode=code: UTF-8 source code, suitable for grep, diff, or model analysis.mode=component: CallsVBComponent.Export; forms include an accompanying.frx.- The output directory will contain a
_manifest.json(type, line count, byte count, SHA-256, skipped/failed entries);overwritedefaults tofalse.
Security Boundaries (Explicitly Stated in the README)
During bridging, AutomationSecurity=3 is set; reading and writing source code will not incidentally execute macros in the workbook, and the plugin provides no “run macro” tool. The bridge runs Python with the host user’s permissions, which bypasses the DSH file sandbox. Password-protected VBA projects cannot be edited. Saving causes Excel to rewrite the entire package, so the bytes will change; in production environments, keep backups and perform business validations.
Installation and Activation¶
After publishing to npm, the installation command is:
dsh plugin add dsh-vba-bridge
For local development directories, you can install via a bundle link (replace the path with your local repository location):
plugin_manager action=install_bundle target=F:\MyProjects\dsh\vba_bridge
After installation, call vba_doctor first. It will list issues one by one, such as missing Python, missing pywin32, AccessVBOM not enabled, Excel failing to start, and provide fix suggestions.
Prerequisites¶
- Windows + desktop Microsoft Excel (the README records local testing on version 16.0.20430.20182).
- Python 3.10+ with
pywin32installed:
pip install pywin32
By default, python in the PATH is used; it can be specified via the pythonPath configuration or the DSH_VBA_PYTHON environment variable.
3. Enable “Trust access to the VBA project object model” in Excel’s Trust Center, e.g., via the registry:
HKCU\Software\Microsoft\Office\16.0\Excel\Security\AccessVBOM = 1
This is a global switch that allows local programs to read and write VBA; it is a security decision and should not be opened casually on untrusted machines.
4. Target files must be in macro-enabled formats; .xlsx files will return NOT_MACRO_ENABLED.
Configuration¶
The installation row id is vba-bridge; defaults can be found in the repository’s cordis.patch.yml:
| Key | Default | Description |
|---|---|---|
pythonPath |
Empty → python (then DSH_VBA_PYTHON) |
A Python environment with pywin32 |
bridgePath |
Empty → bridge/vba_bridge.py inside the package |
A custom bridge script |
timeoutMs |
240000 |
Timeout for a single tool call |
allowWrite |
true |
When false, vba_write_module is rejected immediately |
maxOutputChars |
200000 |
Upper limit for truncating tool output |
After modifying, reload the plugin (disable/enable) or restart the Harness; alternatively, you can override it in the profile’s patch layer by row id vba-bridge. The current version has not yet exported a Config schema; the above keys are configured via patch rather than a settings page form.
Typical Usage¶
In the session, you can use natural language, for example:
- “Check what VBA modules exist in
D:\book.xlsm“ - “Read the source code of
Module1“ - “Write this code into
Module1, and make a backup first” - “Export all modules of
MyVBALibrary.xlamtoF:\dump“ - “List what event handler procedures are in
FRM_PictureViewer“
When explicit parameters are needed, refer to the JSON examples in the README:
{"file": "D:\\book.xlsm"}
{"file": "D:\\book.xlsm", "module": "Module1"}
{"file": "D:\\book.xlsm", "module": "Module1", "code": "Sub Hello()\r\n MsgBox \"hi\"\r\nEnd Sub\r\n", "mode": "replace"}
{"file": "D:\\book.xlsm", "outDir": "D:\\dump", "mode": "component", "overwrite": true}
{"file": "D:\\book.xlsm", "module": "FRM_PictureViewer"}
When debugging the bridge script directly without going through the Harness (in the plugin repository directory):
python bridge\vba_bridge.py inspect fixtures\sample.xlsm
python bridge\vba_bridge.py read fixtures\sample.xlsm Module1
python bridge\vba_bridge.py export fixtures\sample.xlsm work\export --mode component
python bridge\vba_bridge.py procedures fixtures\sample.xlsm Module1
Applicable Scenarios and Caveats¶
Who It Is For
- Scenarios where you are already using DSH on Windows to maintain business macros in
.xlsm/.xlamfiles and want AI to list projects, read and modify modules, batch export, and verify on the Excel side. - Scenarios where you need to export VBA source code as text for diffing, or back up the
.frm/.frxcomponents of UserForms.
Limitations (Listed in the README)
- Writing/exporting depends on desktop Excel; without Excel, only offline read-only access is possible, and component types in offline mode are approximate.
- Forms only support the code region; designer editing is not supported. Currently, it does not run macros.
- There is no
allowedRootspath whitelist;.xlsb/.xlshave not been tested separately (.xlsm/.xlamhave been tested). - A single call typically takes about 5–15 seconds, depending on Excel startup, antivirus software, and whether reopening for verification is performed.
Recommendations Before Installation
The plugin runs Python with the permissions of the current DSH process user and accesses any workbook path you provide. Before installation, review the GitHub source code and the MIT license; only install trusted versions and use it only on trusted workbooks; allowWrite=false can reduce the risk of accidental writes in read-only scenarios.
Common error codes include: VBA_TRUST_DISABLED (AccessVBOM not enabled), PROJECT_PROTECTED (project is password-protected), FILE_LOCKED (workbook is in use), PYWIN32_MISSING, etc. The README’s error code table provides corresponding handling instructions.
Conclusion¶
dsh-vba-bridge consolidates the operations of Excel VBA projects into COM/VBIDE and a set of Harness tools: start with a vba_doctor self-check, then proceed to inspect, read/write, export, and list procedures; writes include backups and reopening for verification. If you are working with desktop Excel macros in DSH, you can learn more about the entry from the community directory page and view the full README and docs/feasibility.md on GitHub.
- Community Directory: https://www.skillhub.cn/plugins/alexltr/dsh-vba-bridge
- Repository: https://github.com/alexltr/dsh-vba-bridge