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

Closing Excel via VBA Code 2

Status
Not open for further replies.

peterpcu

MIS
Sep 15, 2005
31
0
0
GB
Hi,

Any suggestions on what the vba code is to cause a workbook and Excel to close without a save prompt.

I would like to attach this code to a command button on a userform so that when the user clicks the 'close' command button, the userform ends and Excel closes without any further prompts.

Regards

Pete
 
peterpcu,
from excel help:
DisplayAlerts Property Example

This example closes the workbook Book1.xls and doesn’t prompt the user to save changes. Any changes to Book1.xls aren’t saved.

Application.DisplayAlerts = False
Workbooks("BOOK1.XLS").Close
Application.DisplayAlerts = True

regards,
longhair
 
Hi Longhair,

Many thanks for your suggestion which does indeed close the workbook. It still seems to leave Excel open without a workbook in it - so how can I also close down excel as well??

Pete
 
perterpcu,
i believe it is:
application.quit
regards,
longhair
 
Try;

With Application
.ActiveWorkbook.Saved = True
'.Workbooks.Saved = True 'to cover all open Workbooks may work too but I hav'nt tried it
.Quit
end With
 
Thanks to Longhair and Hugh ....both ways worked OK

Pete
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top