The code first.
Sub sRunCARMa()
Dim objXL As Object, x
On Error Resume Next
Set objXL = CreateObject("Excel.Application")
With objXL.Application
.Visible = True
.Workbooks.Open "D:\CARM\SYS\CARMaV5\CARMaV5a.XLS"
.ActiveWorkbook.RunAutoMacros xlAutoOpen
x = .Run("AccountsViewEngine", 0)
End With
Set objXL = Nothing
End Sub
As you can see, I'm using CreateObject to
start an instance of Excel. You can however, use fIsAppRunning function to decide between
CreateObject or GetObject.
CreateObject by defaults starts a new
instance of the application in hidden mode. Hence you need to set the Application object
to Visible.
After opening the workbook in which the
macro is present, use the RunAutoMacros method if you have any AutoOpen macro that you
wish to run.
Note that in order for Access to recognize
xlAutoOpen constant, you need to reference Excel Object Library.
Then simply use the Application.Run method
to run any macros. Note that the syntax I've used is
Run(Macro, Arg1, Arg2, ...)
as the function AccountsViewEngine is
expecting a Boolean argument which the zero satisfies.
|