I have an unmanaged C# DLL that is added to an Excel VBA code.
Private Declare Function DoSomething Lib "myc.dll" Alias "invokePath" (ByVal strRule As String)
Now from within the DLL, I need to know the path of the excel file that has made a request.
I need to then read the values from cells in the Excel workbook from within the C# DLL.
If possible I would implement this as a COM add-in, rather than importing the function from VBA. In this way you will have access to the Excel
Applicationinstance which will be the starting point for fetching data from the spreadsheet and interacting with Excel beyond simply returning a value from the function.If you are calling this as a User Defined Function (UDF) then you will also be able to access the
Application.Callerproperty, which will give you a reference of the cell that triggered evaluation of the UDF.