Calling back vb.net app

  • Thread starter Thread starter John
  • Start date Start date
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
 
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.
 
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
 
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.
 
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
 
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.
 
¤ 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)
 
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


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