> ~/claude-skills/vibeasfunc

Legacy VBA, rewritten as functional C#.

Translates Excel macros, Word automation and Access modules into idiomatic C# on .NET 10, or .NET 8 where a deployment is pinned. Loops become LINQ, error codes become Result types, mutable state becomes immutable records, and I/O moves to the boundary. Written for the specific misery of inheriting a spreadsheet that runs a department.

Why it exists

It was written for the specific misery of inheriting a spreadsheet that runs a department.

A line-by-line transliteration of VBA into C# carries over the two things that make VBA hard to maintain: mutable shared state, and failures hidden behind On Error Resume Next and Variant returns. The result compiles and is no easier to change than the macro was.

So the skill does not translate code. It translates intent. A 200-line Sub is rarely 200 lines of intent; usually it is three or four small ideas mashed together, and the rewrite is the chance to separate them.

Three rules

  1. The pure core has no I/O. Read once, transform purely, write once.
  2. Failures are values, not control flow. Result<T, Error>, not On Error.
  3. State is passed, not shared. No module-level variables, no ActiveSheet, no globals.

Before and after

A macro that sums the large orders on a sheet and shows a message box:

Public Sub BuildSummary()
    Dim i As Long, lastRow As Long
    Dim total As Currency
    lastRow = Sheets("Orders").Cells(Rows.Count, 1).End(xlUp).Row
    For i = 2 To lastRow
        If Sheets("Orders").Cells(i, 2).Value > 1000 Then
            total = total + Sheets("Orders").Cells(i, 2).Value
        End If
    Next i
    MsgBox "Total: " & total
End Sub

becomes a record, one pure function, and a thin boundary:

record Order(string Customer, decimal Amount, DateOnly Date);

static class OrderAnalysis
{
    public static decimal SumLargeOrders(
        IEnumerable<Order> orders, decimal threshold) =>
        orders.Where(o => o.Amount > threshold).Sum(o => o.Amount);
}

// boundary
var orders = OrdersReader.Load("input.xlsx");
var total = OrderAnalysis.SumLargeOrders(orders, 1000m);
Console.WriteLine($"Total: {total:C}");

SumLargeOrders can be tested in milliseconds with no Excel installed. The repository has four worked examples, including a complete Excel pipeline from end to end.

How a translation goes

  1. Find the boundary. What the macro reads and what it writes. Everything in between is the functional core.
  2. Type the inputs and outputs as records, before any logic.
  3. Write the core as pure static functions: no COM, no file I/O, no mutation of inputs.
  4. Write the boundary, the thin code that reads, calls the core and writes. It may be imperative; that is its job.
  5. Turn error handling into values. Each On Error becomes a Result, and the skill states what each swallowed error now does instead.

Before writing any C#, it proposes the architecture and waits for a yes: the target framework, the I/O library (COM interop, ClosedXML or EPPlus) and anything that will not translate directly.

Modes

Argument What happens
(none) Asks for a file or pasted code, analyses it, proposes an architecture, then translates
analyze [path] Reports the constructs found, a complexity rating and a suggested architecture; translates nothing
translate <path> Translates one .bas, .cls, .frm or pasted block
map <construct> Looks up one construct, such as On Error Resume Next, and shows its C# shape
scaffold <name> Creates a console, core and tests solution. Add --framework net8.0 for .NET 8

.NET 10 or .NET 8

The target is .NET 10 unless a deployment is pinned to .NET 8. The skill reads <TargetFramework> or global.json when they exist and asks once when they do not. The two share almost everything; .NET 10 adds some shorter idioms (CountBy, AggregateBy, LeftJoin, extension properties), and the playbook pairs each with its .NET 8 form so that a .NET 8 translation never gets an API it cannot compile.

What it will not do

  • Touch the source. The .xlsm and .bas files are read-only; it only emits C#.
  • Lose numeric or date semantics. Currency maps to decimal, never double. VBA rounds half to even; that is kept or flagged.
  • Guess at COM behaviour. If the macro relies on something Excel does implicitly, such as the active sheet or recalculation, it is flagged, not replaced by a library call that behaves differently.
  • Force everything into a console app. Application.OnTime, event handlers and UserForms are event-driven; it says so and proposes that pattern separately.