G
Guest
I've written the following code to open an Excel workbook and run a macro:
Sub Run_Excel_Macro(f As Variant, m As String) ' f is the Excel filename
and m is the macro
Dim objXL As Object, X, nf
Set objXL = CreateObject("Excel.Application")
DoEvents
With objXL.Application
.Visible = True
.Workbooks.Open (f)
X = Run(m)
objXL.DisplayAlerts = False
objXL.Quit
End With
Set objXL = Nothing
End Sub
It works fine but I only seem to be able to run it once per execution of the
Access application. If I try to run it a 2nd time, the Excel workbook opens
but then I get an error in the Access application. If I close the Access app
and re-open it, I can run it again.
Am I leaving something open? Do I have to do something else after closing
the Excel workbook?
I will appreciate any help I can get.
Miguel
Sub Run_Excel_Macro(f As Variant, m As String) ' f is the Excel filename
and m is the macro
Dim objXL As Object, X, nf
Set objXL = CreateObject("Excel.Application")
DoEvents
With objXL.Application
.Visible = True
.Workbooks.Open (f)
X = Run(m)
objXL.DisplayAlerts = False
objXL.Quit
End With
Set objXL = Nothing
End Sub
It works fine but I only seem to be able to run it once per execution of the
Access application. If I try to run it a 2nd time, the Excel workbook opens
but then I get an error in the Access application. If I close the Access app
and re-open it, I can run it again.
Am I leaving something open? Do I have to do something else after closing
the Excel workbook?
I will appreciate any help I can get.
Miguel