views:

365

answers:

1

I am coding in vb.net through visual studio 2008. I have successfully compiled a dll file from my code but I continue to get "Run-time error '453'" when I try to reference the dll in vba. I understand there is some sort of compiling error that occurs when using vb.net. Does anyone have any suggestions to fix/overcome this issue? I would like to avoid translating the code to another language as much as possible.

Here is a simple sample code that I have been trying to get functioning:

Example.dll:

Public Class Class1

    Function Square(ByVal x As Double, ByRef y As Double)

        y = x * x

        Return 0

    End Function

End Class

Macro in Example.xlsx:

Private Declare Function Square Lib "\Example.dll" (ByRef x As Double, ByRef y As Double)

Sub Test()

Dim x, y As Double

x = 2
y = 0

Call Square(x, y)

MsgBox (y)

End Sub

Thank you, Katlynn

A: 

Its been a while since I've done this so I'm not sure if its necessary anymore but did you try adding all of the COM attributes?

http://support.microsoft.com/Default.aspx?kbid=817248

Chris Haas
Yes, I tried using COMclass1 instead of the default Class1, and the "Register for COM Interop" box was already checked. The code above still produced the error. I've also tried adding the dll as a reference and I get an error like "Can't reference this file" or something silly like that. I also tried building an object like the website you provided suggests but the object doesn't build properly. I feel like there is a loop hole I'm not seeing...Any other advice?
BHurst