Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.excel.programming,microsoft.public.dotnet.languages.csharp
|
|||
|
|||
How to call functions of a DLL in Excel and in a .net project
Hi all,
Thanks in advance for the help I have a DLL that which has several functions that I can call in Excel. I am thinking of how to call these functions in a .net project (authored in C#). I guess I need to describe how I used the DLL in Excel to motive this discussion 1. Here is the way that I can use it in Excel -- (I figured this out with some effort) a. If I just start Excel and type in a cell something like: =DLLFunction(parameterList) I know the function name and parameterList. It won't work (Excel does not recognize the function). b. I also opened the VB editor, from Tools -- Reference, I tried to add the DLL, it won't work. It prompts: "Can't add a reference to the specified file" c. Luckily, I was provided with a template Excel file (.xls) in which it contains two Macros [DLL_Open and DLL_Close]. I cannot edit/delete these two Macros. I can only run these two Macros. Anyways, without doing nothing on these two Macros, after I just opened the template Excel file and if I type in a cell something like: =DLLFunction(parameterList) The function works beautifully. d. If I open VB editor when the template Excel file is open, I can see (in the VBA project panel) there is a project called theDLLProject, which is presumably the "entity" that referce to the DLL in question. ======================================= OK, here is what I am interested to do: 1. How do I call the functions in the DLL in a freshly created Excel file? I can certainly save the template file as another file and call the function. I am interested to know how to configure a new Excel file to recognize this DLL 2. Is it possible that I can call the functions in this DLL in a .net project authored in C#? I tried to add reference to this DLL in a C# project (Project-- Add Reference), it won't work. Thank you very much for your input. DL |
#2
Posted to microsoft.public.excel.programming,microsoft.public.dotnet.languages.csharp
|
|||
|
|||
How to call functions of a DLL in Excel and in a .net project
1) You have to declare the functions of the dll in a vba macro in order
to do that. For example : Declare Function DoCalculation Lib "YourDll" (ByVal value As Long) As Long 2) You have to use PInvoke, .NET's mechanism for calling unmananaged Dlls. For a comprehensive reference you can check : http://msdn2.microsoft.com/en-us/lib...3k(VS.80).aspx Regards, Tasos |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
call a excel function from a vb project | Excel Programming | |||
Can you call functions between sheets in the same book in excel? | Excel Worksheet Functions | |||
Referencing Call to Another Project | Excel Programming | |||
Can I call my .Net functions from Excel Macros | Excel Programming | |||
How to call COM Add-In functions from a macro | Excel Programming |