ExcelReference From Other Worksheet?

Skip to first unread message

Andrew DeBear

Jun 27, 2023, 5:24:24 PMJun 27
to Excel-DNA
I am put together a UDF (C_Formula) that looks up and puts cell values of a formula into a string.


Everything was working as expected for cell references on the same sheet. I'm running into a problem when it references a cell on another worksheet. 

          entered formula     = C_Formula(A3)
          should lookup         = C_Formula("=Sheet2!A1")
          should return           = 50



strCell = strSheet + strCell;

ExcelReference refCell = (ExcelReference)Excel(xlfIndirect, strCell, true);

object objCell = refCell.GetValue();

strCell = ToolsArgs.GetStr(objCell);


When the code gets to the line:
ExcelReference refCell = (ExcelReference)Excel(xlfIndirect, strCell, true); (Line 173 in attached PDF),

Excel freezes for a minute and then crashes with no exception being thrown. The Visual Studio output log just lists:
The program '[12104] EXCEL.EXE' has exited with code 3762504530 (0xe0434352).

Any chance someone can point out what I'm doing wrong? Thanks!

Andrew DeBear

Jun 27, 2023, 5:25:34 PMJun 27
to Excel-DNA
Like I said, attached PDF...
new 1.pdf

Andrew DeBear

Jun 28, 2023, 3:13:25 PMJun 28
to Excel-DNA
Still putzing with this, I just tried turning all of the exceptions, Started the debugger, reset to the Visual Studio to "restore the list to default settings", and started it again.

After I reset, the output log showed this, but not sure how to interpret it, yet...

15:06:00:755 'EXCEL.EXE' (CLR v4.0.30319: FullTrustSandbox(Excel-DNA: C:\Users\%username%\...\Add-Ins\UDFakhC\bin\Debug\UDFakhC-AddIn64.xll)): Loaded 'Anonymously Hosted DynamicMethods Assembly'.
15:06:00:755 Exception thrown: 'System.AccessViolationException' in ExcelDna.Loader
15:06:04:947 The program '[23992] EXCEL.EXE' has exited with code 3762504530 (0xe0434352).

Govert van Drimmelen

Jun 28, 2023, 5:30:07 PMJun 28
to Excel-DNA
If would be helpful to know what string you are passing to the xlfIndirect function when it causes Excel to crash.


Andrew DeBear

Jun 29, 2023, 10:58:36 AMJun 29
to Excel-DNA
Hi, Govert. If the formula in cell D5 is entered as "=C_Formula(A5)", the string being passed refCell is "Sheet2!A1".




Andrew DeBear

Sep 19, 2023, 2:24:05 PMSep 19
to Excel-DNA
Just getting the chance to look back into this, but getting nowhere.

Any ideas why this line is causing Excel to crash when debugging?

          (ExcelReference)Excel(xlfIndirect, "Sheet2!A1", true);

On another test workbook, I tried Excel's native Indirect function to another worksheet and it worked as expected.

Reply all
Reply to author
0 new messages