473,545 Members | 2,081 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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(pa rameterList)
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(pa rameterList)
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 2597
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
4838
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 follows: Type Complex Real As Double Imag As Double End Type
13
1558
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 1. we can add extern "C" keyword, or 2. use the object in C++ code as struct in C.
39
6491
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. When it completes, it can call a success, or a failure function. The names of these success, or failure functions will differ, and I'd like to know...
6
1179
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 GBWPipeline.PipelineService(); string xml = pipeline.GetOfferSale(OfferSheetId, CustomerId).GetXml(); I get a "There is an error in XML document. (1, 220)" message. If I...
7
5882
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 route. The problem being that I can't call these functions from the query designer in Access. I decided that I would try the route of declaring the...
17
6312
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
3479
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 when clicked invokes the web service. It works when I invoke the non secure web service. But
9
4174
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 GetType GetHashCode Equals
0
18767
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 recently (and I know others have come across this recently too) is rounding up and down. I know the Excel ROUNDUP() function rounds away from zero rather...
0
7408
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7661
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
7763
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
1
5340
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
3458
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3444
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1891
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1020
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
712
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.