none
Calling Outlook VBA Procedure From Excel RRS feed

  • Question

  • Hello:

    The folks on the "Excel side of the house" have been trying to find a way to call a VBA procedure (Sub or Function) from Excel that exists in Outlook.  In other words, suppose that there is a VBA Sub called HelloWorld which resides in Outlook.  We want to be able to execute "HelloWorld" from Excel.

    What we have done so far is to include the Outlook library in the Excel application, and tried this code below (which resides in Excel), which is not allowed:

     

    Sub test()
    Dim OutApp As Object
    Set OutApp = CreateObject("Outlook.Application")
    OutApp.Session.Logon
    OutApp.HelloWorld
    
    End Sub
    
    
    Regards,

     


    Rich Locus, Logicwurks, LLC

    http://www.logicwurks.com



    • Edited by RichLocus Wednesday, December 28, 2011 5:48 PM
    Wednesday, December 28, 2011 5:47 PM

Answers

  • Hi Rich,

     

    Thanks for posting in the MSDN Forum.

     

    It’s based on my experience that your goal is hard to address. Outlook doesn’t provide some property which like Excel application’s VBProject property to access its VBA Project. I will involve some experts into this thread to see whether they have some solutions. There might be some time delay, appreciate your patience.

     

    Have a good day,

     

    Tom


    Tom Xu [MSFT]
    MSDN Community Support | Feedback to us
    • Marked as answer by RichLocus Wednesday, January 4, 2012 1:44 AM
    Friday, December 30, 2011 6:07 AM
    Moderator

All replies

  • Hi Rich,

     

    Thanks for posting in the MSDN Forum.

     

    It’s based on my experience that your goal is hard to address. Outlook doesn’t provide some property which like Excel application’s VBProject property to access its VBA Project. I will involve some experts into this thread to see whether they have some solutions. There might be some time delay, appreciate your patience.

     

    Have a good day,

     

    Tom


    Tom Xu [MSFT]
    MSDN Community Support | Feedback to us
    • Marked as answer by RichLocus Wednesday, January 4, 2012 1:44 AM
    Friday, December 30, 2011 6:07 AM
    Moderator
  • Tom:

    Thank you for researching this.  If not possible, we will just recreate the Outlook procedures in the Excel procedure.

    Regards,


    Rich Locus, Logicwurks, LLC

    http://www.logicwurks.com

    Friday, December 30, 2011 6:45 PM
  • Hi Rich,

    Unfortunately, Outlook VBA is architecturally different than VBA in Word and Excel and this scenario is not really supported. Outlook VBA is implemented as a demand-loaded COM add-in, and it's takes user-interaction to demand-load it in Outlook. So scenarios like this were just never really designed to work. You would really need to move this Outlook VBA code into Excel and automate Outlook from Excel.

    This is quite dated, but still relevant for Outlook 2003-2010:

    292177 OL2002: Calling a VBA Procedure from VBScript
    http://support.microsoft.com/default.aspx?scid=kb;EN-US;292177

    (FWIW, this article should ideally be generalized, but VBScript was the focus here since most customers in this scenario were trying to call VBA procedures from VBScript in Outlook custom forms.)

     


    Bill Jacob - Microsoft Customer Service & Support - Developer Messaging
    Thursday, January 5, 2012 3:19 PM
    Moderator