Dennis
Dennis

Reputation: 139

DLL created in C# does not show members when referenced in Excel-VBA

I am new to C# and am trying to create DLLs with functions that I can use in VBA. I have created a test DLL with simple functions that work fine when referenced in another C# assembly. I am also able to reference the DLL in VBA, and the class created by it (named FunctionsVS) appears in the object browser.

In VBA, I have the following code snippet:

Sub Test1()
    Dim z As Integer
    Dim func As New FunctionsVS
    z = func.Add(4, 5)           
End Sub

When I run this sub, I get I get an error message stating

"Class not registered".

I have tried to register the DLL with regsvr32 but I get an error stating:

The module "c:\windows\system32\functionslibframework.dll" was loaded but the entry point DllRegisterServer was not found.

Any advice would be greatly appreciated.

The C# code I used to create the DLL is:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace FunctionLibVS
{
    public class FunctionsVS
    {
        public int Add(int x, int y)
        {
            return x + y;
        }

        public int Multiply(int x, int y)
        {
            return x * y;
        }
    }
}

Upvotes: 0

Views: 212

Answers (1)

Generate the tlb file using regasm.exe regasm /tlb /codebase functionslibframework.dll

Then reference the *.tlb in VBA in Project -> References

Upvotes: 0

Related Questions