JavaScript-like scripting language implemented entirely in VBA. Zero COM dependencies. Native Office object model integration with runtime monkey patching capabilities.
Dim engine As New ASF
engine.Run engine.Compile("return [1,2,3,4,5].filter(fun(x){ return x > 2 }).reduce(fun(a,x){ return a+x }, 0)")
Debug.Print engine.OUTPUT_ ' => 12ASF VS Code extension provides syntax highlighting and language support.
| ✔️ | Live Coding 🚀 |
|---|---|
| VS Code Integration | ![]() |
Language Features:
- Full JavaScript-like syntax with lexical scoping
- First-class functions, closures, and arrow function equivalents
- ES6+ array methods (
map,filter,reduce,find, etc.) - Object/array literals with spread/rest operators
- Classes with inheritance (
extends,super) - Built-in regex engine with lookarounds
- Template literals and destructuring assignment
VBA Integration:
- Seamless VBA Object model integration.
- A lot of advanced function available through VBA-Expressions via
@(...)syntax - Variable injection between VBA and ASF contexts
- Native array/collection marshalling
- Error containment and debugging support
Architecture:
- Pure VBA implementation (no external dependencies)
- Sandboxed VM execution with call stack tracing and toggle configuration for object model accessibility
- 32-bit and 64-bit Office compatibility
- Module system with import/export support
ASF can dynamically extend native Office objects at runtime using prototype-based monkey patching:
// Extend Excel ListRow objects with custom methods
prototype.COM.ListRow asDictionary() {
let headers = this.parent.listcolumns;
let values = this.range.value2;
let result = {};
for (let i = 1, i <= headers.count, i+=1) {
result.set(headers.item(i).name, values[1][i]);
};
return result;
};
// Usage: ListRows now have .asDictionary() method
let data = $1.Sheets(1).ListObjects('Table1').ListRows.map(
fun(row) { return row.asDictionary().get('email'); }
);This enables:
- Runtime method injection into COM objects
- JavaScript-like method chaining on Office objects
- Functional programming patterns on traditional VBA collections
- Context-aware
thisbinding preserving COM object references
The OverrideCollMethods option replaces native VBA collection behavior with JavaScript array semantics:
' Enable collection override (USE WITH CAUTION)
engine.OverrideCollMethods = TrueThis transforms VBA Collections into JavaScript-like arrays with:
- Array iteration methods (
map,filter,forEach) - Immutable operations (
slice,concat,toSorted) - Modern array methods (
find,includes,at) - Destructuring and spread operator support
- Download the latest release
- Import these class modules into your VBA project:
ASF.cls(main engine)ASF_Compiler.clsASF_VM.clsASF_Parser.clsASF_Globals.clsASF_ScopeStack.clsASF_Map.clsASF_RegexEngine.clsUDFunctions.clsVBAcallBack.clsVBAexpressions.clsVBAexpressionsScope.cls
Sub HelloASF()
Dim engine As New ASF
Dim idx As Long
' Compile ASF code
idx = engine.Compile("print('Hello from ASF!')")
' Run it
engine.Run idx
End SubScenario: Filter and sum sales data over $1000
Sub ProcessSalesData()
Dim engine As New ASF
Dim script As String
script = _
"sales = [850, 1200, 950, 2500, 1100, 600];" & _
"highValue = sales.filter(fun(x) { return x > 1000 });" & _
"total = highValue.reduce(fun(sum, item) { return sum + item }, 0);" & _
"return total;"
engine.Run engine.Compile(script)
Debug.Print "High-value sales total: $" & engine.OUTPUT_ ' => $4800
End SubCall VBA-Expressions functions from ASF using @(...):
' In UDFunctions.cls
Public Function GetTaxRate(fakeArg As Variant) As Variant
GetTaxRate = 0.08
End Function
' In your VBA code
Sub CalculateTotal()
Dim asfGlobals As New ASF_Globals
asfGlobals.ASF_InitGlobals
asfGlobals.gExprEvaluator.DeclareUDF "GetTaxRate", "UserDefFunctions"
Dim engine As New ASF
engine.SetGlobals asfGlobals
Dim script As String
script = _
"price = 100;" & _
"tax = price * @(GetTaxRate());" & _
"return price + tax;"
engine.Run engine.Compile(script)
Debug.Print "Total with tax: $" & engine.OUTPUT_ ' => $108
End SubThat's it! You're now using modern scripting in VBA.
NOTE: VBA function calls require a single
Variantparameter as per VBA-Expressions requirements.
- Lexical Analysis: Pure VBA tokenizer with support for ES6+ syntax
- Parsing: Recursive descent parser generating AST nodes
- Compilation: AST transformation with scope analysis and optimization
- Execution: Stack-based virtual machine with proper
thisbinding
- Lexical Scoping: Proper closure capture with environment chains
- Prototype Chain: JavaScript-like prototype inheritance
- Call Stack Management: Proper tail call handling and stack overflow protection
- Memory Management: Automatic garbage collection for ASF objects
- Error Handling: Contained exceptions with full stack traces
- Complex Data Processing: ETL pipelines, JSON parsing, nested transformations
- Dynamic Business Logic: User-configurable rules without VBA recompilation
- Functional Programming: When
map/filter/reducepatterns improve readability - Office Object Extension: Adding custom methods to native Excel/Word objects
- Developer Productivity: Rapid prototyping with familiar JavaScript syntax
- Performance-Critical Code: Tight loops processing millions of items
- Direct COM Interop: Extensive Office API manipulation
- Memory-Constrained Environments: When every KB matters
- Type Safety Requirements: Compile-time checking and IntelliSense
Use ASF for complex logic and VBA for performance hotspots:
' ASF for business logic
Dim businessRules As String: businessRules = "return data.filter(fun(x) { return x.status == 'active' }).map(fun(x) { return x.value * 1.08; })"
Dim processedData As Variant: processedData = engine.Run(engine.Compile(businessRules))
' VBA for bulk Excel operations
Range("A1").Resize(UBound(processedData), 1).Value2 = Application.Transpose(processedData)' ❌ Won't work
engine.Compile("arr = " & Join(myArray, ","))
' ✅ Correct
engine.InjectVariable "arr", myArray
engine.Compile("print(arr[1])")' ❌ Won't work
script = "Range('A1').Value2 = 10"
' ✅ Use placeholder pseudo injection
script = "$1.Range('A1').Value2 = 10"
pid = engine.Compile(script)
engine.Run pid, ThisWorkbook.Sheets(1)- Issues: GitHub Issues
- Pull Requests: Include comprehensive tests
- Documentation: Examples and technical deep-dives welcome
- Enterprise Support: Tag issues with "Enterprise"
MIT License - Copyright © 2026 W. García
Modern scripting for VBA. Zero compromises.
📚 Documentation • 🐛 Report Bug • 💡 Request Feature • ⭐ Star on GitHub

