Exposing vb.net procedures

  • Thread starter Thread starter John
  • Start date Start date
J

John

Hi

How can I expose procedures (function or sub) in my vb.net app to vba in
word?

Thanks

Regards
 
Hi John,

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.
 
Hi

How do I save the vb.net app as activex dll? Is activex dll supported in
..net apps?

Thanks

Regards
 
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

<Assembly: AssemblyKeyFile("C:\Events
Manager\Contacts\EventHelper\EventHelper\EventHelper.snk")>

Namespace MyCompany.EventHelper

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
 
Back
Top