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 biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Run macro on save 1

Status
Not open for further replies.

mleosu

Technical User
Sep 26, 2006
56
US
I have a spreadsheet that is used to request new location information - and have built in a macro tied to a command button to validate the fields to ensure all information is provided. The problem is that the end user does not HAVE to click this button and can save the file with errors.

I have searched for preventing save, macro on save, and such but have not found anything that would help. I thought about tieing the validation macro to the save as (since it is a template so you have to save as) but I am not sure what or where to post this in the VBA.

Any help is appreciated.
 
Have a look at the Workbook_BeforeSave event procedure and its Cancel argument.

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
Thanks PHV - I copied the validation code into the Workbook_BeforeSave - and if there were any errors then it wont allow a save - so it works!

- problem is that now I cant save the changes to the Macro without it going through all the validation code and telling me I have errors
 
okay - i included in the code that if all fields were empty then save is allowed - now i get the error (Compile Error in Hidden Workbook: This Workbook)

What the heck does that mean?
 
Do you know the difference between ThisWorkbook and ActiveWorkbook ?

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top