Debugging

Every call to JuliaCall/JuliaCallVBA/JuliaEval/JuliaEvalVBA leaves a trace behind in Julia, so a problem can be debugged at the REPL without needing to repeat the call from Excel:

  • CallFromExcel.last_question is the expression that was evaluated - either the exact string passed to JuliaEval/JuliaEvalVBA, or, for JuliaCall/JuliaCallVBA, a reconstructed call such as myfunction(CallFromExcel.args_from_xl...). A call of your own worksheet function, =jl.myfunction(...), appears in the same way, with args_from_xl as the function receives them (vectors for arguments declared ::AbstractVector, and so on). A formula creating a handle appears as a call of CallFromExcel.handle_create (or handle_create_exposed, for a function exposed with handle=true), whose first argument is the name of the function it calls (the Excel name, for handle_create_exposed).
  • CallFromExcel.last_answer is the value that was returned to Excel or, if the call failed, the message Excel was sent.
  • CallFromExcel.args_from_xl holds the arguments most recently passed from Excel to JuliaCall/JuliaCallVBA, or the positional arguments for JuliaCallNamedArgs/JuliaCallNamedArgsVBA. For those, CallFromExcel.kwargs_from_xl holds the named arguments as a NamedTuple, and last_question is a call such as myfunction(args_from_xl...; kwargs_from_xl...).
  • CallFromExcel.answer_again() evaluates last_question again, and you can wrap it with @enter or your own debugging tools.

All of these only reflect the most recent call, so debug before making another one. Call CallFromExcel.display_results(true), or tick Display Results on the ribbon, to also have each call and its result echoed to the Julia console as it happens.

For handles:

  • =JuliaHandleInfo("count") shows how many handles worksheet formulas hold, and how many objects Julia stores. If Julia stores more than the formulas hold, the difference is handles created from VBA and not yet released.
  • =JuliaHandleInfo("events") lists recent creates and releases, newest last - for example, to see whether a formula creates a new object at every recalculation.
  • =JuliaHandleInfo("objects") lists every object Julia holds, with its handle and its size in bytes - for example, to see which handles use the most memory.
  • The ribbon's Rebuild Objects button rebuilds every handle's object, as happens when Julia restarts. From VBA, Application.Run "JuliaRebuildObjects" does the same.

To step through your code with a debugger, attach a Julia session you already have open, such as one in VS Code - see Attaching to a running Julia session.