0

If I have workbook with ranges:

Inputs = Sheet1!A1:A10, Scope: Workbook
Sheet1!Inputs = Sheet1!B1:B10, Scope: Worksheet/Sheet1

If I activate Sheet1, the following results occur:

XlCall.Excel( XlCall.xlfGetName, $"!Inputs" ) => =R1C2:R10C2.
XlCall.Excel( XlCall.xlfGetName, $"!Inputs", 2 )=> true indicating that it is scoped to the worksheet

If I activate a different sheet and make the same calls, I get the following:

XlCall.Excel( XlCall.xlfGetName, $"!Inputs" ) => =Sheet1!R1C1:R10C1.
XlCall.Excel( XlCall.xlfGetName, $"!Inputs", 2 )=> false indicating that it is scoped to the workbook.

If I delete my worksheet scoped Name and repeat the process. Calling when Sheet1 is active yields:

XlCall.Excel( XlCall.xlfGetName, $"!Inputs" ) => =R1C1:R10C1. Note C1
XlCall.Excel( XlCall.xlfGetName, $"!Inputs", 2 )=> false indicating that it is scoped to the workbook.

If I activate a different sheet and make the same calls, I get the following:

XlCall.Excel( XlCall.xlfGetName, $"!Inputs" ) => =Sheet1!R1C1:R10C1.
XlCall.Excel( XlCall.xlfGetName, $"!Inputs", 2 )=> false indicating that it is scoped to the workbook.

Problem: I don't see an easy way to get a Workbook vs Worksheet scoped Name via C API. The best way I can think to do it is to call xlfGetName with the info_type parameter and ensure it is returning the proper value based on requested scope.

If they get the incorrectly scoped Name, then change the active sheet (based on requested scope) appropriately and try again.

Is that the best method? Is there something I'm missing from the C API documentation I'm reading?

3
  • Have you tried doing this with OLE automation instead? It's slower, but easier. Even if you don't like that approach, trying it might tell you what's wrong with your code that uses the C API.
    – Jim Foye
    Commented Jun 5 at 19:00
  • When I said "OLE automation" I meant still within Excel-DNA, btw.
    – Jim Foye
    Commented Jun 5 at 19:19
  • Yes, but I need to be running on async thread for my process which prevents me from (safely) using COM.
    – Terry
    Commented Jun 7 at 17:39

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.