473,399 Members | 3,656 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,399 software developers and data experts.

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

May 27 '06 #1
1 2590
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

May 27 '06 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Socrates | last post by:
Hello, I have a problem building and using an activeX dll. I would appreciate it if anyone could help: I have written some complex functions. I have a complex type with .real and ..imag part as...
13
by: Mike Qin | last post by:
Hi there, Now I'm writing code mainly in C++. And some existing c code will call some functions which are in a C++ class. I read the basic techniques introduced from a SUN's web site. Basically...
39
by: Randell D. | last post by:
Folks, I'm sure this can be done legally, and not thru tricks of the trade - I hope someone can help. I'm writing a 'tool' (a function) which can be used generically in any of my projects. ...
6
by: Colin Young | last post by:
I am creating some code that runs in Excel using VSTO. I am trying to get some xml from a webservice, using the following code: GBWPipeline.PipelineService pipeline = new...
7
by: Tim ffitch | last post by:
Hi I have created a VB dll file that contains common functions I use across various projects in VB, Access and Excel. Rather than have to code the functions in each I decided to use the dll...
17
by: Mansi | last post by:
I need to do some research on how to use excel automation from c#. Does anyone know of any good books related to this subject? Thanks. Mansi
1
by: mron0210 | last post by:
Hi, I have created a web service using Visual Studio .Net (Visual Studio Tools for Office : Excel project) and secured it using WSE 2.0. I have added a hyperlink in the Excel sheet which...
9
by: Torben Laursen | last post by:
Hi I have a class that I use in Excel to define some custom functions. The problem that I have is that the class also has some building functions that for some reason is there: ToString...
0
NeoPa
by: NeoPa | last post by:
Many of us have noticed that there are some very useful functions available to you when using Excel, but these same functions are not available, as standard, in Access. A particular issue I had...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.