Pass class reference

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

John

Hi

I open a word document from my vb.net app. Now I want to pass reference to
one of the classes in my vb.net app to word so it can access procedures in
the vb.net class. How can I pass the class reference to word from a vb.net
app?

Thanks

Regards
 
John said:
I open a word document from my vb.net app. Now I want to pass
reference to one of the classes in my vb.net app to word so it can
access procedures in the vb.net class. How can I pass the class
reference to word from a vb.net app?

You can't. Word doesn't know your app.
 
I have created a com Class Library in .net and have placed a references to
it both in Word and in my vb.net app so they should both know about the same
class.

Are you saying there is now ay to call procedures in vb.net from word, even
via a com library?

Regards
 
John said:
I have created a com Class Library in .net and have placed a
references to it both in Word and in my vb.net app so they should
both know about the same class.

Are you saying there is now ay to call procedures in vb.net from
word, even via a com library?

The Word COM objects that you reference in your VB.NET application do not
know your class because they have been developped before your library. Maybe
it is possible in the Word object model to set a reference back to the
library, but only late binding would be possible. Anyway, when should it
make sense to pass your own object? I think Word can not deal with it
anyway.

If you reference your VB.NET COM library in Word VBA, you can use your
library, but what you are asking for is the case above.
 
All I need at this point is to pass a reference to a COM library class to
word. I am doing this from vb.net which has the reference to this COM class.

Regards
 
John said:
All I need at this point is to pass a reference to a COM library
class to word. I am doing this from vb.net which has the reference to
this COM class.

To which Word object or method do you want to pass the object?
 
Here is some of my code in word;

Public Caller As EventHelper.EventHelper
Public Sub SetCaller(ByRef x As EventHelper.EventHelper)
Caller = x
End Sub

I would ideally like the caller variable to have the class reference
assigned so I can call the vb.bet com class from word using the reference,
as follows;

Call ActiveDocument.Caller.RaiseWordDocSaved(ActiveDocument)

The word (and vb.net app) knows about the EventHelper.EventHelper class as
it is a com class and is referenced by both word and vb.net. Basically I am
using the class to make word communicate with vb.net app. The code for the
com class is given at the end below. If there is an easier way for word vba
to call a procedure in my vb.net app then I would like to know.

Thanks

Regards


' File:EventHelper.vb
Imports System
Imports System.Reflection
Imports System.Runtime.InteropServices

<Assembly: AssemblyKeyFile("C:\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
 
I would use a "physical" intermediaire like: an ASCII file or even the
registry
to push/pull values from one app to the other.

As far as the registry is concerned, look at below articles for
Word writing to/reading from registry settings
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vbawd10/htm
l/woproprivateprofilestring.asp

Example of MS Office registry functions
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/office97/ht
ml/output/f1/d6/s5b239.asp

Example of VB .net registry functions
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vblr7/html/
vafctgetsetting.asp


Krgrds,
Perry
 
Back
Top