How do you kill excel on the machine when you run another report that opens up excel. It is telling me it can not because exzcel is open already.
Thanks
If you look at the links on the site, you'll see that there is a download of the MS Office Automation help files, in these is the info you are looking for :
You can use the following function to determine if an instance of Microsoft Excel is running.
Function IsExcelRunning() As Boolean
Dim xlApp As Excel.Application
On Error Resume Next
Set xlApp = GetObject(, "Excel.Application"
IsExcelRunning = (Err.Number = 0)
Set xlApp = Nothing
Err.Clear
End Function
And then, your code can determine whether it needs to create a new instance or not…
Sub ExcelInstance()
Dim xlApp As Excel.Application
Dim ExcelRunning As Boolean
ExcelRunning = IsExcelRunning()
If ExcelRunning Then
Set xlApp = GetObject(, "Excel.Application"
Else
Set xlApp = CreateObject("Excel.Application"
End If
'Other automation code here...
If Not ExcelRunning Then xlApp.Quit
Set xlApp = Nothing
End Sub
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.