I have an Excel file that contains public constants in a user-created module, and I need to read those constants from a C# application.
In the Excel VBA I have in a module called CellDefinitions
e.g.:
Public Const PROJECT_ID_RANGE As String = "A18"
Here is what I have tried from C#, but it obviously doesn't work, since constants are not macros:
var excel = new Microsoft.Office.Interop.Excel.Application();
Workbook wb = excel.Workbooks.Add(excelTemplateFile);
var value = excel.Run("CellDefinitions.PROJECT_ID_RANGE");
The Excel file has the constants also as properties, but they cannot be read from C#, since they are located in ThisWorkbook
module (see Access return value from VBA Function in .NET?).
Note that I cannot edit the Excel file or its VBA code (to e.g. create new functions in a new module), so I'm looking for a solution only for the C# part.