Create dll file and call it from Excel worksheet or macro

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Could some one provide a step-by-step instruction on:

(1) Create a public function, such as

Public Function Addition(double A, double B) As Double
Addition=A+B
End Function

Public Function Subtraction(double A, double B) As Double
Subtraction=A-B
End Function


(2) compile it to a Addition.dll or to a *.dll file which contains both
Addition and Subtraction?

so that (3) in an Excel worksheet, we just use
=Addition(C1, C2)
To carry on a calculation?

Thanks!
 
With a slight change, you can put the functions in a regular module in
Excel's VB Editor and use it. The change is "A as Double" rather than
"double A". A dll can't be made in Excel; VB, VB.NET, C++, etc. is
needed.

Hth,
Merjet
 
Thanks, Merjet.

But my need is to use dll instead using macro in order to hide the code. I
have vb.net and can compile dll file for ASP use. For example, I only need
specify the name space and add lot of #include system statement, put the dll
file in the same folder or server, then the ASP can pick up all functions.

For Excel, what are the procedures should I follow, and the objective is to
use the use defined function just like the Excel buid-in functions such as
=sum(C1:C10), =Median(C1:C10), etc.

In the Macro VB, I can also directly call the dunction, like A=exp(10), etc.

Thanks for your response.

FindSolution
 
FindSolution said:
Could some one provide a step-by-step instruction on:

(1) Create a public function, such as

Public Function Addition(double A, double B) As Double
Addition=A+B
End Function

Public Function Subtraction(double A, double B) As Double
Subtraction=A-B
End Function


(2) compile it to a Addition.dll or to a *.dll file which contains both
Addition and Subtraction?

so that (3) in an Excel worksheet, we just use
=Addition(C1, C2)
To carry on a calculation?

Thanks!

If you don't mind using C#:

http://www.codeproject.com/dotnet/excelnetauto.asp
 
I haven't used vb.net. I've used VB6 to make a DLL, and guess it's
similar. So I will answer from that background. A DLL has one or more
Public objects of which a calling application can make an instance of.
The Public object will have properties and/or methods that can be
used.

For example, here are some lines of code from a project.
Public moCntrl As Calm.Cntrl
Set myCntrl = New Calm.Cntrl

Calm is a DLL. Cntrl is a Public class which has several Public
objects and methods.

To use the DLL In Excel, it will need a reference in the VB Editor
using the menu Tools | References.

Hth,
Merjet
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top