2

I have this code in outlook thisoutlooksession:

Public Sub hello2()
  MsgBox "Hello world !!"
End Sub

I want to call this sub from vb.net with the following code. i made all the necessary reference to outlook and office:

Sub Main()
    Dim olApp As New Outlook.Application
    Dim olNs As Outlook.NameSpace
    olNs = olApp.GetNamespace("MAPI")

    Try
        olApp.hello2()
    Catch ex As Exception
        Console.WriteLine(ex.ToString())
    Finally
        olApp = Nothing
        olNs = Nothing
    End Try
End Sub

however i keep getting Public member 'hello2' on type 'ApplicationClass' not found.

Can someone help?

ThunderFrame
  • 9,352
  • 2
  • 29
  • 60
  • 1
    I think you're looking for the Application.Run method, which unfortunately doesn't exist in the Outlook Object Model (unlike Excel, Word etc.) As a workaround, you *might* be able to set up an Outlook Rule, and use the Rule.Execute method - https://msdn.microsoft.com/en-us/library/office/ff864433.aspx – ThunderFrame Mar 28 '16 at 00:34
  • I see..you will think Microsoft would allow application run in outlook just like it does for most the application in office suite. – Ohuanasis Garcia Mar 28 '16 at 20:32
  • 1
    The [Linked Post](http://stackoverflow.com/questions/31954364/how-can-i-run-a-macro-from-a-vbe-add-in-without-application-run) did eventually work out how to use a CommandBarButton as a proxy for `Application.Run`. – ThunderFrame Dec 23 '16 at 01:14

0 Answers0