Project Files
dist / tools / vba.js
"use strict";
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = { enumerable: true, get: function() { return m[k]; } };
}
Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
o["default"] = v;
});
var __importStar = (this && this.__importStar) || (function () {
var ownKeys = function(o) {
ownKeys = Object.getOwnPropertyNames || function (o) {
var ar = [];
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
return ar;
};
return ownKeys(o);
};
return function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
__setModuleDefault(result, mod);
return result;
};
})();
Object.defineProperty(exports, "__esModule", { value: true });
exports.getVbaTools = getVbaTools;
const sdk_1 = require("@lmstudio/sdk");
const zod_1 = require("zod");
const XLSX = __importStar(require("xlsx"));
const path = __importStar(require("path"));
const config_1 = require("../utils/config");
function getVbaTools() {
return [
// ── 28. excel_read_vba ───────────────────────────────────────────────────
(0, sdk_1.tool)({
name: "excel_read_vba",
description: "Extract and display VBA module code from a macro-enabled Excel file (.xlsm). Requires a .xlsm file. VBA creation is not supported (requires Python+openpyxl).",
parameters: {
filePath: zod_1.z.string().describe("Path to a .xlsm file"),
},
implementation: async ({ filePath }) => {
const err = (0, config_1.checkReadable)(filePath);
if (err)
return `Error: ${err}`;
const ext = path.extname(filePath).toLowerCase();
if (ext !== ".xlsm")
return `Error: VBA reading requires a .xlsm file. Got: ${ext}`;
try {
const wb = XLSX.readFile(filePath, { bookVBA: true });
if (!wb.vbaraw)
return "No VBA project found in this file.";
// Write raw VBA binary to temp, then try to parse module names from it
const vbaBuffer = Buffer.from(wb.vbaraw, "binary");
// Extract module names and code snippets from VBA binary (text search)
const vbaStr = vbaBuffer.toString("latin1");
const modules = [];
const moduleMatches = [...vbaStr.matchAll(/Attribute VB_Name = "([^"]+)"/g)];
if (moduleMatches.length > 0) {
for (const match of moduleMatches) {
const name = match[1];
// Extract code between Attribute blocks (heuristic)
const start = match.index ?? 0;
const snippet = vbaStr.substring(start, start + 500)
.replace(/[\x00-\x08\x0b-\x1f\x7f-\x9f]/g, " ")
.trim();
modules.push({ name, preview: snippet });
}
}
return JSON.stringify({
file: filePath,
vba_present: true,
vba_size_bytes: vbaBuffer.length,
modules_found: modules.length,
modules,
note: "VBA binary extracted. For full source editing, use Excel or Python+openpyxl.",
}, null, 2);
}
catch (e) {
return `Error: ${e}`;
}
},
}),
];
}
//# sourceMappingURL=vba.js.map