I have a UDF non-volatile function in VBA, which requires a global variable (callback to VSTO) initialized.
This function resides in xla or xlam (same behaviour)
Is there a way to cancel calculation of the formula if the variable not yet available?
In Excel Automatic recalculation mode (I don’t want to change that) Excel recalculates cells with my function every time I open a workbook, replacing value saved in a cell with error: “#ARG!”.
I know how to return empty cell if my variable is not initialized, but is it possible to return original value? I checked with a debugger that it has been saved in the workbook. Trying to return Application.Caller.Value2 causes cyclic reference.
Also, the function isn’t called (expected behaviour) if the VBA code is embedded in the workbook (xlsm), or if the workbook is in xls format. However, converting a workbook to xlsx causes the cells to be recalculated after workbook is opened as described.
I eventually went with the xlsm approach.