Check for array formula within a macro-style Excel UDF

287 views Asked by At

I'm using Excel-DNA to create UDFs within Excel and NetOffice for version-independent automation calls. Within a macro-type function, I'm able to use the following to get the formula from a cell:

ExcelReference cellRef; // of course in reality this is assigned
var formula = (string)this.excelCall(XlCall.xlfGetFormula, cellRef);

Additionally though, I'd like to know whether this is part of an array formula, and if so what its extent is. Using Excel automation, I can use something like:

Range("A1").HasArray
Range("A1").CurrentArray.Address

However, Microsoft discourage the use of automation within UDF calls: https://support.microsoft.com/en-us/kb/301443

So, is there a way to get the the HasArray and CurrentArray properties via the C API, or does anyone know if it's okay (in the context of a UDF declared as macro-type) to use automation?

1

There are 1 answers

2
Govert On

The GET.CELL information function, with information type_num 49 will return whether the cell is part of an array. From your Excel-DNA (macro-type) function:

bool isArray = (bool)XlCall.Excel(XlCall.xlfGetCell, 49, cellRef);