none
Access to VBA form C# RRS feed

  • Question

  • Hello,

    I would like to know if it is possible to reach the VBA of Outlook from C#.

    That's what I try to do to call a macro:
    olApplication.GetType().InvokeMember("Run", BindingFlags.Default | BindingFlags.InvokeMethod, null, olApplication, new object[]{MyMacroName});

    It works on Excel, but with Outlook I get the following error:
    System.Runtime.InteropServices.COMException (0x80020006): Unknown name. (Exception from HRESULT: 0x80020006 (DISP_E_UNKNOWNNAME))

    With Excel, I can reach the VBA in this way, but not with Outlook:
    xlApplication.ActiveWorkbook.VBProject

    Monday, November 11, 2013 12:41 PM

Answers

  • Outlook no longer allows you to reach procedures in the VBA ThisOutlookSession class.

    In earlier versions of Outlook you could create a Public Sub or Function in ThisOutlookSession and if it was named say "Foobar" it could be called as Outlook.Application.Foobar().

    That was never officially supported by MS, and it now has been removed from Outlook.


    Ken Slovak MVP - Outlook

    Wednesday, November 13, 2013 6:49 PM
    Moderator
  • Hi,

    According to your description, you want to reach the VBA of Outlook from C#, however you encounter an exception when running the code.

    The reason why you will get “Unknown name” error is: Outlook.Application doesn’t contain a “Run” method.

    For more information, please refer HOW TO: Run Office Macros by Using Automation from Visual C# .NET.


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Wednesday, November 13, 2013 8:03 AM
    Moderator

All replies

  • Hi,

    According to your description, you want to reach the VBA of Outlook from C#, however you encounter an exception when running the code.

    The reason why you will get “Unknown name” error is: Outlook.Application doesn’t contain a “Run” method.

    For more information, please refer HOW TO: Run Office Macros by Using Automation from Visual C# .NET.


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Wednesday, November 13, 2013 8:03 AM
    Moderator
  • I should prefer access a VBA object rather than using a method as "Run".

    I had already found this page. The problem is that it concerns Excel, PowerPoint and Word, but not Outlook.
    Wednesday, November 13, 2013 9:09 AM
  • Outlook no longer allows you to reach procedures in the VBA ThisOutlookSession class.

    In earlier versions of Outlook you could create a Public Sub or Function in ThisOutlookSession and if it was named say "Foobar" it could be called as Outlook.Application.Foobar().

    That was never officially supported by MS, and it now has been removed from Outlook.


    Ken Slovak MVP - Outlook

    Wednesday, November 13, 2013 6:49 PM
    Moderator
  • Ok, that's what I thought, but I was expecting an "official" answer.
    Thank you for your help.
    Thursday, November 14, 2013 7:43 AM