• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 390
  • Last Modified:

Call .NET method from within Outlook Macro

Hey all

I would like to do the following: Allow someone to call a method in a VB.NET application from within an Outlook 2007 Macro. Sort of a transfer of control if you will. Is there any way to do that and if so how?

I would then use this method to do everything I have to on the .NET application. The reason I want to do it this way is because of automation purposes and making it easier on the user.

Also if the application is closed, is there a way to open the application and still leave authentication(log in screen) in check and then after that still run the method as per usual?

Thank you
  • 2
4 Solutions
I dont see it as possible. You can not make method calls on EXEs. What you can possibly do is call the exe with command line arguments but it gives you limited functionality.
Corey ScheichDeveloperCommented:
You can do this using .Net Remoting and a com Registered class.


if you com register the ipcClient you can make calls to it from an out of process macro.  This method can also be used to talk across the 32/64bit divide.

the page above has a c# example
Corey ScheichDeveloperCommented:
For example in the macro you could have the following code

Sub main()
Dim client As New RemotingLibrary.client

Dim Frm As New RemotingLibrary.formController

Frm.SetText ("I set the text")

End Sub

with the following .Net code

Once you have registered the client channel you can then create instances of the registered object and the instances are running in the remote process though they look local to the macro.

Imports System.Runtime.Remoting.Channels
Imports System.Runtime.Remoting.Channels.Ipc
Imports System.Runtime.Remoting
Public Class formController
    Private Shared frm As MyApplicationForm
    Sub New()
        If formController.frm Is Nothing Then
            formController.frm = New MyApplicationForm
        End If
    End Sub
    Sub SetText(ByVal Value As String)
        formController.frm.TextBox1.Text = Value
    End Sub
End Class
Public Class RemoteServer
    Public Sub New()
        ChannelServices.RegisterChannel(New IpcChannel("Remote"), False)
        RemotingConfiguration.RegisterWellKnownServiceType(GetType(RemotingLibrary.formController), "MyAppForm", WellKnownObjectMode.Singleton)
    End Sub
End Class
Public Class Client
    Public Sub New()
        ChannelServices.RegisterChannel(New IpcClientChannel, False)
        RemotingConfiguration.RegisterWellKnownClientType(GetType(RemotingLibrary.formController), "ipc://Remote/MyAppForm")
    End Sub
End Class

Open in new window

culminITAuthor Commented:
I have found a solution here: http://stackoverflow.com/questions/375457/cant-instantiate-a-com-object-written-in-c-from-vba-vb6-ok
Also here (forms part of other solution): http://www.thewayofcoding.com/tag/regasm/

Thanks for the help
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Get your problem seen by more experts

Be seen. Boost your question’s priority for more expert views and faster solutions

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now