I'm trying to interface
vb.net objects with Excel VBA with Excel DNA. I based it on converting the example provided by Michael Katajamaki (
http://mikejuniperhill.blogspot.com/2014/03/interfacing-c-and-vba-with-exceldna-no.html) from c# to
vb.net.
I can't quite make it work, the ExcelInterface2.xll file loads in Excel, but when running the vba code I get an error "ActiveX component can't create object." I'm using VS2010 to create the dll.
The complete code is provided below. I really appreciate any help.
Paul
'************************************************************
Imports System
Imports ExcelDna.Integration
Imports ExcelDna.ComInterop
Imports System.Runtime.InteropServices
<ComVisible(True)>
<ClassInterface(ClassInterfaceType.AutoDispatch)>
<ProgId("HelloWorld")>
Public Class InterfaceFunctions
Public Sub New()
ComServer.DllRegisterServer()
End Sub
Public Function add(ByVal x As Double, ByVal y As Double) As Double
Return x + y
End Function
Protected Overrides Sub Finalize()
MyBase.Finalize()
ComServer.DllUnregisterServer()
End Sub
End Class
'**************************************************************
ExcelInterface2.dna file
'******************************************************************
<DnaLibrary Language="VB" RuntimeVersion="v4.0">
<ExternalLibrary Path="ExcelInterface2.dll" />
</DnaLibrary>
'******************************************************************
VBA code
'**************************************************************************
Option Explicit
'
Sub tester()
'
Dim lib As Object: Set lib = CreateObject("HelloWorld")
Debug.Print lib.Add(12, 13)
Set lib = Nothing
End Sub
'*******************************************************************
'Here's a listing of files in the directory with the xll file
ExcelInterface2.dll
ExcelInterface2.dna
ExcelInterface2.xll