ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Don't let user close. Use macro button to close? (https://www.excelbanter.com/excel-programming/376129-dont-let-user-close-use-macro-button-close.html)

mike

Don't let user close. Use macro button to close?
 
How can I force this? Can I?

I need to make sure the workbook is saved before it's closed, make sure
it's not closed without being saved. I have a "Close" button that goes
to a macro that saves.

I thought of putting a save macro in as workbook.deactivate code, but
then my button would be redundant.

Should I just lose the button and stick with workbook.deactivate?


Jim Thomlinson

Don't let user close. Use macro button to close?
 
How about in the before close event add in the save. Add this code to the
ThisWorkbook module (right click the XL icon next to the word file in Excel
and select View Code)

Private Sub Workbook_BeforeClose(Cancel As Boolean)
If Not ThisWorkbook.Saved Then ThisWorkbook.Save
End Sub

--
HTH...

Jim Thomlinson


"mike" wrote:

How can I force this? Can I?

I need to make sure the workbook is saved before it's closed, make sure
it's not closed without being saved. I have a "Close" button that goes
to a macro that saves.

I thought of putting a save macro in as workbook.deactivate code, but
then my button would be redundant.

Should I just lose the button and stick with workbook.deactivate?



mike

Don't let user close. Use macro button to close?
 
Yeah I'll just delete the button and stick with this method.

Thanks.

Jim Thomlinson wrote:
How about in the before close event add in the save. Add this code to the
ThisWorkbook module (right click the XL icon next to the word file in Excel
and select View Code)

Private Sub Workbook_BeforeClose(Cancel As Boolean)
If Not ThisWorkbook.Saved Then ThisWorkbook.Save
End Sub

--
HTH...

Jim Thomlinson


"mike" wrote:

How can I force this? Can I?

I need to make sure the workbook is saved before it's closed, make sure
it's not closed without being saved. I have a "Close" button that goes
to a macro that saves.

I thought of putting a save macro in as workbook.deactivate code, but
then my button would be redundant.

Should I just lose the button and stick with workbook.deactivate?





All times are GMT +1. The time now is 04:50 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com