1 Replies - 8048 Views - Last Post: 23 August 2013 - 09:55 AM Rate Topic: -----

#1 el_timtor   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 14-February 11

Excel.EXE process remains in Task Manager after quitting application.

Posted 19 August 2013 - 12:37 PM

Hello, all.
I have a VBA procedure in Access 2007 that creates a recordset and outputs it to an Excel spreadsheet (code follows). Everything is normal until the 'cleanup' phase, where the worksheet closes and Excel quits. The process tab in Task Manager still shows EXCEL.EXE running (and there will be multiple instances of EXCEL.EXE if I run the procedure multiple times). I am open to suggestions from the community. I also apologize if this is the wrong place for this question, I figured since I was running this in Access, this would be where to post...

'runs order intake query and outputs results to order intake spreadsheet
Private Sub cmdOrdIntk_Click()
    DoCmd.SetWarnings False
    stDocName = "qryOrderIntake"
    DoCmd.RunSQL ("DELETE * FROM OrderIntake") 'clear temp table
    DoCmd.OpenQuery stDocName, acViewNormal, acReadOnly 'populate temp table with new data
    DoCmd.SetWarnings True
    Dim c As ADODB.Connection  'this code sets up ADODB connection and recordset,...
    Dim rs As New ADODB.Recordset
    Connection = "Provider='Microsoft.ACE.OLEDB.12.0';Data Source='C:\Documents and Settings\nx3422\My Documents\My Projects\CTKReports_Dev.mdb';" _
    & "Persist Security Info='False';"
    Set c = CurrentProject.Connection
    rs.Open "SELECT * FROM OrderIntake", c
    Dim x As New Excel.Application '...opens the spreadsheet and finds the correct tab, ...
    Dim w As Workbook
    Dim s As Worksheet
    Dim r As Range
    Dim d As String

    d = "C:\Documents and Settings\nx3422\My Documents\My Projects\ExcelSpreadsheets\"
    x.Visible = True
    Set w = Workbooks.Open(d & "CTKOrderIntake.xls")
    Set s = w.Sheets("Data")
    Set r = s.Range("J2")
    r.CopyFromRecordset rs  '...populates the data page,...

    s.Columns("J:O").Font.Name = "Calibri"
    s.Columns("J:O").Font.Size = 11

    Dim dtSave As String  '...saves with the current date,...
    dtSave = Format(Date, "ddmmmyyyy")
    w.SaveAs (d & "CTKOrderIntake_" & dtSave & ".xls"), xlWorkbookNormal, , , False, , xlExclusive
    rs.Close  '...and cleans everything up.
    Set rs = Nothing
    Set c = Nothing
    Set r = Nothing
    Set s = Nothing
    Set w = Nothing
    Set x = Nothing

End Sub

As I understand things, "x.Quit" above is what closes Excel, but I am at a loss as to why the process does not end.

Is This A Good Question/Topic? 0
  • +

Replies To: Excel.EXE process remains in Task Manager after quitting application.

#2 mojo666   User is offline

  • D.I.C Addict
  • member icon

Reputation: 408
  • View blog
  • Posts: 882
  • Joined: 27-June 09

Re: Excel.EXE process remains in Task Manager after quitting application.

Posted 23 August 2013 - 09:55 AM

I had a similar issue before. As best as I can tell, X.quit is equivalent to hitting the "x" icon on an excel window. That closes the app unless it has some prompts that it needs the user to answer. In my case, after reading through the file it was brining up a "save changes?" prompt after I submitted the quit command. The following csharp code is how I got it to actually close. My memory is a little foggy, but I think the first line was the one that actually did the trick.

wrkbk.Close(false, Type.Missing, Type.Missing);

if (excelApp != null)

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1