PDA

View Full Version : What I did wrong with Excel VBA in connection with DLL?



jiura
09-11-2008, 05:19 AM
In Visual Basic I did a DLL file with such code:


Public Function Summa(x As Integer, y As Integer) As Integer
Summa = x + y
End Function

I called my class module as ?cl1?, and dll project and file name as ?dll100?
Then I create New excel File AT THE SAME folder, and in VBA "module 1" write such code:


Public Declare Function Summa Lib "dll100" (ByVal x As Integer, ByVal y As Integer) As Integer
Public Sub hh()
'Dim Sum As Long
Sum = Summa(15, 20)
MsgBox Sum
End Sub

It gave me an error message that Excel cannot find it! But WHY? If the dll file is in the same folder as Excel file, and I also know AND HAVE project witch is declares function on such case:


Declare Sub CreateForm Lib "PrjWTest" ()
Declare Function MyTest Lib "PrjWTest" (ByVal Ns As Byte) As String
Declare Sub FreeForm Lib "PrjWTest" ()

AND EVERYTHING IS PERFECTLY WORK AFTER THE FIRST RUN. In this project ?PrjWTest? is a DLL file in the same folder as an Excel or Word file and everything is worked!
I want to do such thing to call some DLL functions when my Excel program install on other computer.

Second! Ok I write the full path to my dll library:


Public Declare Function Summa Lib "C:\Documents and Settings\JIura\Desktop\DLL\03\dll100.dll" (ByVal x As Integer, ByVal y As Integer) As Integer


Excel gives me the second mistake that it: ?453 Can?t find DLL?s entry point Summa in C:\Documents and Settings\JIura\Desktop\DLL\03\dll100.dll?.
What is this? What I did wrorg?

Can you help me with this two questions?

Bob Phillips
09-11-2008, 05:58 AM
Try registering the DLL.