Consulting

Results 1 to 3 of 3

Thread: Run a macro stored in Microsoft Excel

  1. #1

    Run a macro stored in Microsoft Excel

    Hello,

    I would like some Outlook VBA code to execute a macro which is stored in a Microsoft Excel workbook from Microsoft Outlook 2007.

    I know the equivalent in Excel VBA is:

    Application.Run (wbname & "!procedurename)

    but this does not work in Outlook VBA.

    Can someone help please?

    thanks
    andy

  2. #2
    VBAX Expert JP2112's Avatar
    Joined
    Oct 2008
    Location
    Astoria, NY
    Posts
    590
    Location
    Just create an instance of Excel, open the workbook and use the run method as you've described. Here's some air code:

    [VBA]Function runXLMacro(wbname As String, procedurename As String)
    ' wbname = file and path of workbook containing the macro you want to run
    ' procedurename = name of the Excel macro you want to run

    Dim xlApp As Object
    Dim xlwb As Object
    Set xlApp = GetExcelApp
    Set xlwb = xlApp.Workbooks.Open (wbname)

    xlApp.Run (wbname & "!procedurename)

    End Function

    Function GetExcelApp() As Object
    ' always create new instance
    On Error Resume Next
    Set GetExcelApp = CreateObject("Excel.Application")
    On Error GoTo 0
    End Function
    [/VBA]

    Quote Originally Posted by neodjandre
    Hello,

    I would like some Outlook VBA code to execute a macro which is stored in a Microsoft Excel workbook from Microsoft Outlook 2007.

    I know the equivalent in Excel VBA is:

    Application.Run (wbname & "!procedurename)

    but this does not work in Outlook VBA.

    Can someone help please?

    thanks
    andy

  3. #3
    ok this is helpful but the Excel Workbook is already open.

    I don't want to create a new Excel instance.

    If I do that then Macros will be automatically disabled and I get an error message that the macro cannot run because they are not enabled in Excel.

    Your code needs to be modified so that it recognises the Excel instance already open!

    thanks a lot again
    andy

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •