You can make classes and methods visible to COM and use the DLL within
your VBA application. You will find a sample for using a .NET DLL from
within VB6 here:
The VB.NET project must be saved as an ActiveX DLL. Then you can access the
DLL either by setting a reference in Tools References in the VBA editor, or
by using late binding, and creating an object variable with the reference
using the CreateObject command.
I never did like the ComClass attribute. I prefer the absolute control
of ComVisible, ProgId, Guid and ClassInterfaceType in conjunction with
interfaces.
--
There are 10 kinds of people. Those who understand binary and those who
don't.
OK, I am slowly trying to get the hang of things. At the bottom is what I
have come with as something I can call from Word VBA. When I build it I get
two files one dll and other tlb. Can I just add these to references in Word
and start using or do I need to do something else before that?
Thanks
Regards
Imports System
Imports System.Reflection
Imports System.Runtime.InteropServices
Public Interface IEventHelper
Event WordDocSaved(ByRef Doc As Object)
Event WordDocPrinted(ByRef Doc As Object)
Function Instance() As IEventHelper
Sub RaiseWordDocSaved(ByRef Doc As Object)
Sub RaiseWordDocPrinted(ByRef Doc As Object)
End Interface
<ClassInterface(ClassInterfaceType.None)> _
Public Class EventHelper
Implements IEventHelper
Public Event WordDocSaved(ByRef Doc As Object) Implements
IEventHelper.WordDocSaved
Public Event WordDocPrinted(ByRef Doc As Object) Implements
IEventHelper.WordDocPrinted
Private Shared _Instance As EventHelper
Public Function Instance() As IEventHelper Implements IEventHelper.Instance
If (_Instance Is Nothing) Then
SyncLock GetType(EventHelper)
If (_Instance Is Nothing) Then
_Instance = New EventHelper
End If
End SyncLock
End If
Return _Instance
End Function
Public Sub RaiseWordDocSaved(ByRef Doc As Object) Implements
IEventHelper.RaiseWordDocSaved
RaiseEvent WordDocSaved(Doc)
End Sub
Public Sub RaiseWordDocPrinted(ByRef Doc As Object) Implements
IEventHelper.RaiseWordDocPrinted
RaiseEvent WordDocPrinted(Doc)
End Sub
End Class
End Namespace
Ask a Question
Want to reply to this thread or ask your own question?
You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.