ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Saving VBA project on workbook close (https://www.excelbanter.com/excel-programming/367357-saving-vba-project-workbook-close.html)

Eric Fingerhut[_3_]

Saving VBA project on workbook close
 
Sorry if this is an obvious one. I want to have code to protect myself from
closing a project without saving changes. The code below just doesn't execute
the save although the logic hits the line.

TIA, Eric

in Thisworkbook

Private Sub Workbook_BeforeClose(Cancel As Boolean)
Cancel = Not Shutdown(ThisWorkbook)
If Cancel Then
Call ThisWorkbook.Save
Debug.Assert ThisWorkbook.Saved
Cancel = False
End If
End Sub


NickHK

Saving VBA project on workbook close
 
Eric,
What is Shutdown ?

NickHK

"Eric Fingerhut" wrote in message
...
Sorry if this is an obvious one. I want to have code to protect myself

from
closing a project without saving changes. The code below just doesn't

execute
the save although the logic hits the line.

TIA, Eric

in Thisworkbook

Private Sub Workbook_BeforeClose(Cancel As Boolean)
Cancel = Not Shutdown(ThisWorkbook)
If Cancel Then
Call ThisWorkbook.Save
Debug.Assert ThisWorkbook.Saved
Cancel = False
End If
End Sub




Corey

Saving VBA project on workbook close
 
Sub Macro1()
Application.DisplayAlerts = True
ActiveWorkbook.Save ' saves active workbook
Application.Quit ' exits Excel
End Sub


Corey....



EricF

Saving VBA project on workbook close
 
Doesn't work for me, at least not in Workbook_BeforeClose

"Corey" wrote:

Sub Macro1()
Application.DisplayAlerts = True
ActiveWorkbook.Save ' saves active workbook
Application.Quit ' exits Excel
End Sub


Corey....




NickHK

Saving VBA project on workbook close
 
You need to provide more details if you want constructive help.
What are supposed to make of "Doesn't work for me" ?

NickHK

"EricF" wrote in message
...
Doesn't work for me, at least not in Workbook_BeforeClose

"Corey" wrote:

Sub Macro1()
Application.DisplayAlerts = True
ActiveWorkbook.Save ' saves active workbook
Application.Quit ' exits Excel
End Sub


Corey....







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

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