469,354 Members | 2,170 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,354 developers. It's quick & easy.

Pass class reference

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
Nov 20 '05 #1
7 2156
"John" <jo**@nospam.infovis.co.uk> schrieb

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

http://www.plig.net/nnq/nquote.html
http://www.netmeister.org/news/learn2quote.html

Nov 20 '05 #2
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
"Armin Zingler" <az*******@freenet.de> wrote in message
news:Og**************@TK2MSFTNGP12.phx.gbl...
"John" <jo**@nospam.infovis.co.uk> schrieb

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

http://www.plig.net/nnq/nquote.html
http://www.netmeister.org/news/learn2quote.html

Nov 20 '05 #3
"John" <jo**@nospam.infovis.co.uk> schrieb
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.
--
Armin

http://www.plig.net/nnq/nquote.html
http://www.netmeister.org/news/learn2quote.html

Nov 20 '05 #4
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
"Armin Zingler" <az*******@freenet.de> wrote in message
news:Ol**************@TK2MSFTNGP11.phx.gbl...
"John" <jo**@nospam.infovis.co.uk> schrieb
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.
--
Armin

http://www.plig.net/nnq/nquote.html
http://www.netmeister.org/news/learn2quote.html

Nov 20 '05 #5
"John" <jo**@nospam.infovis.co.uk> schrieb
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?
--
Armin

http://www.plig.net/nnq/nquote.html
http://www.netmeister.org/news/learn2quote.html

Nov 20 '05 #6
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(ActiveDocu ment)

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
"Armin Zingler" <az*******@freenet.de> wrote in message
news:ON**************@TK2MSFTNGP09.phx.gbl...
"John" <jo**@nospam.infovis.co.uk> schrieb
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?
--
Armin

http://www.plig.net/nnq/nquote.html
http://www.netmeister.org/news/learn2quote.html

Nov 20 '05 #7
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/de...us/vbawd10/htm
l/woproprivateprofilestring.asp

Example of MS Office registry functions
http://msdn.microsoft.com/library/de...us/office97/ht
ml/output/f1/d6/s5b239.asp

Example of VB .net registry functions
http://msdn.microsoft.com/library/de...us/vblr7/html/
vafctgetsetting.asp
Krgrds,
Perry

"John" <jo**@nospam.infovis.co.uk> wrote in message
news:ee**************@TK2MSFTNGP11.phx.gbl...
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

Nov 20 '05 #8

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

4 posts views Thread by Todd | last post: by
9 posts views Thread by Jay Douglas | last post: by
4 posts views Thread by z_learning_tester | last post: by
4 posts views Thread by Alexander Kolev | last post: by
12 posts views Thread by Bryan Parkoff | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by suresh191 | last post: by
1 post views Thread by Marylou17 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.