PC Review


Reply
Thread Tools Rate Thread

Can I have code executed after Save?

 
 
robs3131
Guest
Posts: n/a
 
      21st Dec 2007
Hi all,

I'm trying to have a sub called to execute after a workbook is saved --
literally, I would like the code to execute as soon as the file is saved, but
not before, as the sub is storing the name of the workbook in a cell in the
worksheet. I need the name to be current with whatever the name of the
worksheet is at any given time. I see that there is a Workbook level command
that executes before Save, but I don't see anything for after Save.

Thanks for your help!



--
Robert
 
Reply With Quote
 
 
 
 
carlo
Guest
Posts: n/a
 
      21st Dec 2007
Why don't you let Excel enter the filename by itself:
http://office.microsoft.com/en-us/ex...346271033.aspx

hth
carlo

On Dec 21, 3:59*pm, robs3131 <robs3...@discussions.microsoft.com>
wrote:
> Hi all,
>
> I'm trying to have a sub called to execute after a workbook is saved --
> literally, I would like the code to execute as soon as the file is saved, but
> not before, as the sub is storing the name of the workbook in a cell in the
> worksheet. *I need the name to be current with whatever the name of the
> worksheet is at any given time. *I see that there is a Workbook level command
> that executes before Save, but I don't see anything for after Save.
>
> Thanks for your help!
>
> --
> Robert


 
Reply With Quote
 
Héctor Miguel
Guest
Posts: n/a
 
      21st Dec 2007
hi, !

> I'm trying to have a sub called to execute after a workbook is saved -- literally
> I would like the code to execute as soon as the file is saved, but not before
> as the sub is storing the name of the workbook in a cell in the worksheet.
> I need the name to be current with whatever the name of the worksheet is at any given time.
> I see that there is a Workbook level command that executes before Save, but I don't see anything for after Save.
> Thanks for your help!


besides the cell("filename") worksheet function (suggested by carlo)
you can "handle" your _beforesave event to execute a procedure "after_save" if you...

1) use a general code module to define a normal sub-procedure (to be executed "after_save") i.e.

Option Private Module
Sub After_Saved()
MsgBox "This workbook has been saved as:" & vbCr & _
ThisWorkbook.FullName
End Sub

2) in your workbook_beforesave event, use the OnTime method to launch "the sub-procedure"
(which will be executed "after") i.e.

Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As Boolean)
Application.OnTime Now, "After_Saved"
End Sub

hth,
hector.


 
Reply With Quote
 
robs3131
Guest
Posts: n/a
 
      3rd Jan 2008
Thanks Hector and Carlo - that helped!

--
Robert


"Héctor Miguel" wrote:

> hi, !
>
> > I'm trying to have a sub called to execute after a workbook is saved -- literally
> > I would like the code to execute as soon as the file is saved, but not before
> > as the sub is storing the name of the workbook in a cell in the worksheet.
> > I need the name to be current with whatever the name of the worksheet is at any given time.
> > I see that there is a Workbook level command that executes before Save, but I don't see anything for after Save.
> > Thanks for your help!

>
> besides the cell("filename") worksheet function (suggested by carlo)
> you can "handle" your _beforesave event to execute a procedure "after_save" if you...
>
> 1) use a general code module to define a normal sub-procedure (to be executed "after_save") i.e.
>
> Option Private Module
> Sub After_Saved()
> MsgBox "This workbook has been saved as:" & vbCr & _
> ThisWorkbook.FullName
> End Sub
>
> 2) in your workbook_beforesave event, use the OnTime method to launch "the sub-procedure"
> (which will be executed "after") i.e.
>
> Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As Boolean)
> Application.OnTime Now, "After_Saved"
> End Sub
>
> hth,
> hector.
>
>
>

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
VBA code do not get executed Jim Pan Microsoft Access VBA Modules 4 4th Mar 2008 03:33 PM
ORIGINAL CODE GETS EXECUTED NOT THE NEW CODE - ASCX sk Microsoft ASP .NET 1 19th Apr 2006 12:50 PM
No file when Save As is executed =?Utf-8?B?RC5QYXJrZXI=?= Microsoft Excel Programming 15 2nd Apr 2005 12:46 AM
Code Not Getting Executed In VB.NET Phil Galey Microsoft VB .NET 4 3rd Feb 2005 07:27 PM
VB code not executed SB Microsoft Outlook VBA Programming 1 3rd Jun 2004 02:28 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 03:16 PM.