You better C sharp or you'll VB flat
July 1, 2009 4:41 AM

How do you use a Class Library DLL created with C# from VBA?

Here at work, we've got some ancient code that is desperately in need of a rewrite, and I'm a bit of a novice when it comes to all the terminologies and interoperability of bits of Windows code.

What we have now is a DLL written in Visual C++ 5.0.
There is also a VBA piece that runs inside Excel.
The Excel code contains lines that look like this:
Declare Sub subname Lib "dllname" (ByVal Arg1 As String, Arg2 As Long, Arg3 As Long)

I've been tasked with catching up with this century and rewriting the DLL in C#/.NET , with as minimal changes as possible to the other pieces.

I know C# is very Java-like, and I'm just starting to learn it (fairly easy language to pick up).

But is there a way to create a DLL in C# that is accessible using the above "Declare Sub" syntax? If so, what is the syntax? Since C# involves class hierarchies I imagine it's a bit different.

If not, then what is the "proper" way to link to a .NET DLL from VBA? Do I have to "register" the DLL and use COM?
posted by jozxyqk to Computers & Internet (1 answer total)
Looks like you've got to use COM, but also need to take special steps to make sure the DLL can find the .NET framework.
posted by ignignokt at 5:32 AM on July 1, 2009


« Older Is grad school necessary?   |   How to make a 3D model from 2D images Newer »
This thread is closed to new comments.