ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Discussion (Misc queries) (https://www.excelbanter.com/excel-discussion-misc-queries/)
-   -   How do I run a macro upon saving a file but prior to actual save? (https://www.excelbanter.com/excel-discussion-misc-queries/190331-how-do-i-run-macro-upon-saving-file-but-prior-actual-save.html)

Hawk186

How do I run a macro upon saving a file but prior to actual save?
 
Excel 2003 - The user does not want the file to be allowed to save if the
value in a given field does not equal zero. Is there a way to run a macro
when a save is executed?

FSt1

How do I run a macro upon saving a file but prior to actual save?
 
hi
yes there is a before save event. it is thisworkbook code so paste your
macro in the thisworkbook-beforesave

Regards
FSt1


"Hawk186" wrote:

Excel 2003 - The user does not want the file to be allowed to save if the
value in a given field does not equal zero. Is there a way to run a macro
when a save is executed?


Gord Dibben

How do I run a macro upon saving a file but prior to actual save?
 
Private Sub Workbook_BeforeSave(ByVal SaveAsUI _
As Boolean, Cancel As Boolean)
If Sheets("Sheet1").Range("A1") < 0 Then
Cancel = True
MsgBox "Sheet1 A1 is not zero, save has been cancelled"
End If
End Sub


Gord Dibben MS Excel MVP

On Fri, 6 Jun 2008 11:01:01 -0700, Hawk186
wrote:

Excel 2003 - The user does not want the file to be allowed to save if the
value in a given field does not equal zero. Is there a way to run a macro
when a save is executed?




All times are GMT +1. The time now is 12:51 AM.

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