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 bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

CHECK IF EXCEL IS RUNNING

Status
Not open for further replies.

PrgrmsAll

Programmer
Apr 8, 2003
180
US
I have a VB application in which I want to open Excel, populate some cells and then close Excel. This is fairly easy to do. However, I need to determine beforehand, whether or not Excel is running. If it was previously running, I want to only close my workbook. If it was not previously running, I want to close my workbook and indeed the entire Excel application. Has anyone done this with any success?

Thanks in advance.
 
Dim bFlag As Boolean, oXL As Object
On Error Resume Next
Set oXL = GetObject(, "Excel.Application")
If Err.Number = 0 Then bFlag = True
Err.Clear
On Error GoTo 0
If bFlag = False Then Set oXL = CreateObject("Excel.Application")
...
If bFlag Then oXL.Quit

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top