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