Results 1 to 2 of 2

Thread: Calling Excel Macro's from VB .exe

  1. #1

    Thread Starter
    New Member
    Join Date
    Feb 2004
    Posts
    2

    Calling Excel Macro's from VB .exe

    Hi, I have a simple .exe that opens an Excel sheet, runs a macro and closes:

    <code>
    Sub Main()

    'Opens Excel, runs a macro and closes

    Dim xlApp As Excel.Application
    Set xlApp = CreateObject("Excel.Application")
    xlApp.Application.DisplayAlerts = False
    Dim wb As Excel.Workbook
    Set wb = xlApp.Workbooks.Open("C:\book.xls")

    'wb = Excel.Workbook.Open("C:\book.xls")

    ' Make it invisible:
    xlApp.Visible = False

    ' Run the macro:
    xlApp.Run ("formatWattle")

    xlApp.Quit
    Set xlApp = Nothing
    Set wb = Nothing

    End Sub
    </code>

    When I run the macro from within Excel, it executes in about 2 seconds, start to finish. When I call the macro from an .executable, it takes a few minutes, and sometimes just plain crashes on me.

    The .exe is compiled with VB5, since I tried with VB.net and it was just as slow.

    If anyone can tell me how to get better results with what I am doing, please fill me in, as it is difficult to find information on something like this.

    Many thanks,

    .tehwa

  2. #2

    Thread Starter
    New Member
    Join Date
    Feb 2004
    Posts
    2
    just to add another issue, it will execute quickly if the attribute 'xlApp.Visible' is set to 'true', but takes about 30secnds longer if this is set to 'false'.

Posting Permissions

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



Click Here to Expand Forum to Full Width