How do I run a macro upon saving a file but prior to actual save?

  • Thread starter Thread starter Hawk186
  • Start date Start date
H

Hawk186

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?
 
hi
yes there is a before save event. it is thisworkbook code so paste your
macro in the thisworkbook-beforesave

Regards
FSt1
 
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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top