Calling back vb.net app

J

John

Hi

I am opening word from my vb.net app. Is there a way to call a procedure in
the vb.net app from a word macro?

Thanks

Regards
 
S

scorpion53061

why are you posting this to the whole world?

anyway, I would suggest converting the code in the macro to something
useable in vb.net and placing it there thus eliminating the problem.

I can't help anymore without more details.
 
J

John

What I need is that when word does something, it informs the calling vb.net
app. Therefore I need word to be able to communicate with the vb.net app.

Thanks

Regards
 
J

Jonathan West

John said:
What I need is that when word does something, it informs the calling vb.net
app. Therefore I need word to be able to communicate with the vb.net app.

It depends rather on what that something is and the circumstances in which
the VB.NET app is listening.
 
J

John

My example is given at the bottom. I need to call it 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
 
J

Jonathan West

John said:
My example is given at the bottom. I need to call it 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?

That depends on whether the DLL implements a COM interface. If the DLL has a
COM interface, then you will be able to set a reference to it by going to
the Word VBA editor, selecting Tools, References, and then setting a
reference to your DLL.
 
P

Paul Clement

¤ Hi
¤
¤ I am opening word from my vb.net app. Is there a way to call a procedure in
¤ the vb.net app from a word macro?
¤

Using Events would be the best method. You really don't want to have the client and automation
server calling each other:

See if the following helps:

HOWTO: Handle Events for Microsoft Word Using Microsoft Visual Basic .NET
http://support.microsoft.com/default.aspx?scid=kb;en-us;302816&Product=vbNET


Paul ~~~ (e-mail address removed)
Microsoft MVP (Visual Basic)
 
J

John

Yes, I agree. This is what I started with but Word odes not expose
DocumentAfterSave and DocumentAfterPrint which are the two events which I am
after. Anyway my vb.net app can know when the document has been saved and/or
printed?

Thanks

Regards


 
C

Cindy M -WordMVP-

Hi John,
Yes, I agree. This is what I started with but Word odes not expose
DocumentAfterSave and DocumentAfterPrint which are the two events which I am
after. Anyway my vb.net app can know when the document has been saved and/or
printed?
If you intercept the "Before" events, then send the Save resp. PrintOut
commands in your code, the code will wait until the actions have been
processed, then proceed. You just have to make sure you set the Background
printing option to FALSE.

-- Cindy
 

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.

Ask a Question

Top