demo
https://yiminghe.me/kison/examples/vba
npm package
https://www.npmjs.com/package/vba
features
- basic type: integer, array, string, double, date
- expression: not > < <> = >= <= + & * / \ ^ += -= xor and or
- visibility: public/private variable and sub/function
- control logic: with, if then else, do while, for next, for each, goto
- function: sub/function, static variable
- error handling: function top level error handling
- class module
- binding: sub binding and class binding, vba engine even sub binding to provide native vba function/class, such as lbound/ubound/Collection
usage
import { Context, SubBinding } from 'vba';
const sampleCode = `
sub main
debug.print 1
debug.print 2
end sub
`.trim();
const MsgBoxSub: SubBinding = {
name: 'debug.print',
argumentsInfo: [
{
name: 'msg',
},
],
async value(args) {
console.log((await args.getValue('msg'))?.value);
},
};
async function main(){
const context = new Context();
context.registerSubBinding(MsgBoxSub);
await context.load(sampleCode);
await context.callSub('main');
// console log 1 and 2
}
main();