I compiled a dll ‘Trial.dll’ with the following function on a VM (XP) in Windows 7 Public Function Opposite(x As Double) As Double Opposite = -x End Function [code] I registered the dll and made a reference to it in Excel VBA. I use the following code in VBA Private Declare Function Opposite Lib “trial” (x As Double) As Double Sub test() Dim x As Double x = 1 x = Opposite(x) End Sub [code] This gives the error ‘Specified DLL function not found’ (runtime error 453) How can I solve this? Thank you for any suggestion.

Thank you, John. I didn’t think of the object browser. All functions are there subordinate to the class. I have a few quite complicated spreadsheet functions in it and now they are compiled, the program runs 20 times faster.
Theo

With the DLL referenced go to View: Object Browser
In the Upper drop down select Trial
In Globals, see if you can spot your function Opposite()

In your code
Dim objTrial as Object
Set objTrial = New Trial()

Now see if you can use it.

X = objTrial.Opposite( X)

It is a ‘bad sign’ if Intellisense is not happy with the SET line.

Get back to us with the result. To be honest it has been a long time since I did this. If this has failed give us ALL the code in Trial.dll

John Warner

I found the answer to my question in

I have to declare a variable as the class that contains the function.
Thanks to everybody who took a look at the problem.
Theo