Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Response.ContentType = "application/vnd.ms-excel"

Status
Not open for further replies.

zishan619

Programmer
May 28, 2003
284
MX
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
 
Thanks ggriffit but that doesn't answer my question. 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
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top