There's LOTS of reasons for wanting to do this.
Hmm... I take "exception" to ddadmin's comment 
"writing a code around save is not recommended"...

I use the Workbook_BeforeSave event in many of my applications.
(I'm currently maintaining about 130,00 lines of VBA code!)

Here's a couple of uses:
1) I do code testing in a Development file.  When I hit "save", the event 
checks to see if I'm the one that is logged in and is this the file in the 
Development folder.  If so, it asks me if I wish to "publish" the file.  If I 
answer "yes", it fires off a macro that first saves the current file, then 
removes some of my sheets used exclusively for development, then saves the file 
to the Production environment.

2) If the user hitting the "save" button is NOT me, or the file is one in the 
Production environment, then it asks the user for verification, and then 
collects data from the worksheets and names the file based on the contents of 
the cells.

3) I have applications that store data from the workbook to an Oracle database 
rather than to an Excel file.  When the user hits "save", instead of saving the 
FILE, I cancel the default "save" operation and issue commands to update the 
Oracle database.

There's LOTS of perfectly valid reasons to recommend using the Save event.
It's all part of the Design process...

Paul




________________________________
From: ddadmin2009 <ddadmin2...@gmail.com>
To: excel-macros@googlegroups.com
Sent: Tuesday, April 14, 2009 10:14:24 PM
Subject: $$Excel-Macros$$ Re: Autorun a macro on save

Hi Hamster,
I don't know your requirement. But with design perspective writing a code 
around save is not recommended because you might hit save button or Ctrl + S 
many a times unknowingly while working with excel. Just check it out.
have fun,
ddadmin.


On Mon, Apr 13, 2009 at 10:11 AM, Hamster <udo.baumf...@arcor.de> wrote:


Thanks, Dave, that's what I was looking for!

On 3 Apr., 06:54, Dave Bonallack <davebonall...@hotmail.com> wrote:
> Hi Hamster,
>
> If you go to the Workbook window of the VBA, where your Workbook Open macros 
> live, set the left drop-down to Workbook, then in the right drop-down, 
> select:   BeforeSave.
>
> You will se a blank sub like this:
>
> Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As Boolean)
>
> End Sub
>
> Then just put your code in.
>
> Hope this helps.
>
> Regards - Dave.
>
> _________________________________________________________________
> The new Windows Live Messenger has landed. Download it 
> here.http://download.live.com/





-- 
http://funwithexcel.blogspot.com/


--~--~---------~--~----~------------~-------~--~----~
-------------------------------------------------------------------------------------
Some important links for excel users:
1. Excel and VBA Tutorials(Video and Text), Free add-ins downloads at 
http://www.excelitems.com
2. Excel tutorials at http://www.excel-macros.blogspot.com
3. Learn VBA Macros at http://www.vbamacros.blogspot.com
4. Excel Tips and Tricks at http://exceldailytip.blogspot.com
 

To post to this group, send email to excel-macros@googlegroups.com
If you find any spam message in the group, please send an email to:
Ayush Jain  @ jainayus...@gmail.com or
Ashish Jain @ 26may.1...@gmail.com
-------------------------------------------------------------------------------------
-~----------~----~----~----~------~----~------~--~---

Reply via email to