• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1248
  • Last Modified:

Excel process won't end with Application.Quit

I am opening an excel file from vba code in an Access database. After I do what I need to do, the excel process does not end in task manager. How do I kill it?

    Dim xlapp As Object
   
    Set xlapp = CreateObject("Excel.Application")
    xlapp.DisplayAlerts = False
    xlapp.Workbooks.Open "...\my excel file"
    ActiveWorkbook.RefreshAll
   
    xlapp.Wait (Now + TimeValue("0:00:20"))
   
    MsgBox Range("A1").Value & " " & Range("B1").Value
    ActiveWorkbook.Save
   
    xlapp.Quit
    Set xlapp = Nothing
0
seinc
Asked:
seinc
  • 3
  • 2
  • 2
  • +1
1 Solution
 
TimCotteeCommented:
Hi seinc,

Probably because despite setting displayalerts = false there is a dialog or something that you cannot see that is preventing it from quitting.

Try adding xlapp.visible = True in your code and running it to see whether this is the case.

Tim Cottee
0
 
DhaestCommented:
Private Sub Command1_Click()
    Dim xlapp, xlWkb, xlsWSheet As Object
   
    Set xlapp = CreateObject("Excel.Application")
    xlapp.Visible = True
    xlapp.DisplayAlerts = False
    Set xlWkb = xlapp.Workbooks.Open("c:\Book1.xls")
    Set xlsWSheet = xlWkb.ActiveSheet
   
    xlWkb.RefreshAll
     
    xlapp.Wait (Now + TimeValue("0:00:20"))
   
    MsgBox xlsWSheet.Range("A1").Value & " " & xlsWSheet.Range("B1").Value
    xlWkb.Save
    xlWkb.Close
    xlapp.Quit

    ' Cleaning up the variables
    Set xlapp = Nothing
    Set xlWkb = Nothing
    Set xlsWSheet = Nothing
end sub
0
 
seincAuthor Commented:
I tried your suggestion Tim. Excel becomes visible, then goes away after my 20 second delay. No message boxes even if I enable DisplayAlerts. I should also mention that if I click stop in the code editor or close Access, the Excel process ends.
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
seincAuthor Commented:
Used your code, Dhaest , but no change. Any other ideas?
0
 
DhaestCommented:
Was succesfull for me here. Very strange..
Perhaps changing this from place will help
(first the sheet, then the workbook and then the application)
    ' Cleaning up the variables
    Set xlsWSheet = Nothing
    Set xlWkb = Nothing
    Set xlapp = Nothing
0
 
seincAuthor Commented:
Tim, somehow I missed it but there is a message box asking me to save. Since I had supressed it, document recovery kept saving recovery versions of the file. I guess now I need to know why my xlWkb.save is not working.
0
 
PaulHewsCommented:
The problem is on this line:

ActiveWorkbook.RefreshAll

Which should be
xlapp.ActiveWorkbook.RefreshAll

Never use unqualified object references in automation code:
http://support.microsoft.com/kb/178510/
0
 
PaulHewsCommented:
Goes for this too:
ActiveWorkbook.Save

should be

xlapp.ActiveWorkbook.Save

Look through your code for any other "global" object references that should be qualified with the application instance.
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

  • 3
  • 2
  • 2
  • +1
Tackle projects and never again get stuck behind a technical roadblock.
Join Now