Close or Exit application

J

Jeff

I am having trouble closing Excel, ( the Application )
from VBA. I am able to close a specific workbook, but
cannot force Excel the application to close. I am trying
to code a return to desktop, closing entirely the Excel
application. I have tried using,

Workbooks("workbook_Name").close

and

Application.Quit

Both of these methods leave excel and the VBA editor
running. Am using Excel 2000.
 
J

jim c.

this is the code i use to close excel from userform...
***********************************************************
Private Sub CommandButton7_Click()
Unload Me
ActiveWorkbook.Close SaveChanges:=True
Application.Visible = True
Application.Quit

End Sub
***********************************************************

application.quit is what your looking for.....
 
J

John Wilson

jim,

The problem with your code is that you're closing the workbook
before quitting the application.
In your macro, the:
ActiveWorkbook.Close SaveChanges:=True
is the last line of code that is run. Nothing else after that will run.
Try the following:

Private Sub CommandButton7_Click()
Unload Me
ActiveWorkbook.Save
Application.Quit
End Sub

John
 
J

Jeff

Thanks for all the input. Save and then exit works like a
dream. Hadn't thought of the close closing the VB and
thus not running the last statement. Made my morning much
better!
Jeff
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top