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!

Close without saving in Excel 2

Status
Not open for further replies.

AcousticalConsultant

Technical User
Sep 20, 2001
45
CA
Ok here's yet another question...
When the user closes the spreadsheet, I don't want excel to ask me if I want to save my changes. What I tried was this:

Private Sub Workbook_BeforeClose(Cancel As Boolean)

Workbooks("myWorkbook.xls").Close (False)

End Sub

but the problem with this is that I'm closing the workbook before Excel does. So once this module is finished, Excel can't find my workbook that it was asked to close! So I end up getting an illegal operation and Excel closes.

How can I get around this?

Thanks for the help!
Pascal
 
The problem is that the quit command has already started. You can insert this sub into a module (not the workbook or sheet modules). This should take care of your problem.
Code:
Sub Auto_Close()
    ActiveWorkbook.Close (False)
    Application.Quit
End Sub
 
dsi,

Yes, but that's my problem, is that I don't want to automatically close the workbook. Only once the user clicks close or X. But I don't want Excel to prompt the user to save changes!

Is this feasible? The only other way around it that I was able to come up with, is to make a custom button that serves to close the workbook, and we would have to click that button rather than File>Close... but that's kinda' crummy!

Thanks again,
Pascal

 
Try using the Workbook_BeforeClose event...

Private Sub Workbook_BeforeClose(Cancel As Boolean)
ActiveWorkbook.Save
ThisWorkbook.Saved = True
End Sub

vbMax
 
Private Sub Workbook_BeforeClose(Cancel As Boolean)

Workbooks("myWorkbook.xls").Saved = True

End Sub

This would 'tell' Excel that no changes have been made to the workbook since the last save.
Thus, Excel would not ask if you want to save it.

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top