PC Review


Reply
Thread Tools Rate Thread

beforesave code working sometimes......

 
 
=?Utf-8?B?YXdyZXg=?=
Guest
Posts: n/a
 
      29th May 2007
Ok I had posted a question about some code (Subject: Code issue -
before_save() - Filename with date stamp - worksheet), to which I got it to
work but now it is causing my Excel to completely crash.

Any ideas??? Also Why do I get 2 vbok pop up boxes????

Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As Boolean)


MsgBox "You should see something renamed!!", vbOK

Sheet1.Name = "As of " & Format(Now(), "MM-DD-YYYY")

ChDir "<new dir path>"
ActiveWorkbook.SaveAs _
"<MyFileName>" & Format(Now(), "yyyymmdd")

End Sub

 
Reply With Quote
 
 
 
 
=?Utf-8?B?SmltIFRob21saW5zb24=?=
Guest
Posts: n/a
 
      29th May 2007
Your save as is calling a save which is going to be an issue. You need to
cancel the pending save make your changes disable events, save the book and
then re enable... something like this...

Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As Boolean)
On error goto ErrorHandler
Application.enableevents = false
cancel = true
MsgBox "You should see something renamed!!", vbOK

Sheet1.Name = "As of " & Format(Now(), "MM-DD-YYYY")

ChDir "<new dir path>"
ActiveWorkbook.SaveAs _
"<MyFileName>" & Format(Now(), "yyyymmdd")
ErrorHandler:
Application.enableevents = true
End Sub
--
HTH...

Jim Thomlinson


"awrex" wrote:

> Ok I had posted a question about some code (Subject: Code issue -
> before_save() - Filename with date stamp - worksheet), to which I got it to
> work but now it is causing my Excel to completely crash.
>
> Any ideas??? Also Why do I get 2 vbok pop up boxes????
>
> Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As Boolean)
>
>
> MsgBox "You should see something renamed!!", vbOK
>
> Sheet1.Name = "As of " & Format(Now(), "MM-DD-YYYY")
>
> ChDir "<new dir path>"
> ActiveWorkbook.SaveAs _
> "<MyFileName>" & Format(Now(), "yyyymmdd")
>
> End Sub
>

 
Reply With Quote
 
=?Utf-8?B?YXdyZXg=?=
Guest
Posts: n/a
 
      29th May 2007
THANK YOU!!!!!
Works great. Would you happen to know of web reference that I can look at
regarding this.


"Jim Thomlinson" wrote:

> Your save as is calling a save which is going to be an issue. You need to
> cancel the pending save make your changes disable events, save the book and
> then re enable... something like this...
>
> Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As Boolean)
> On error goto ErrorHandler
> Application.enableevents = false
> cancel = true
> MsgBox "You should see something renamed!!", vbOK
>
> Sheet1.Name = "As of " & Format(Now(), "MM-DD-YYYY")
>
> ChDir "<new dir path>"
> ActiveWorkbook.SaveAs _
> "<MyFileName>" & Format(Now(), "yyyymmdd")
> ErrorHandler:
> Application.enableevents = true
> End Sub
> --
> HTH...
>
> Jim Thomlinson
>
>
> "awrex" wrote:
>
> > Ok I had posted a question about some code (Subject: Code issue -
> > before_save() - Filename with date stamp - worksheet), to which I got it to
> > work but now it is causing my Excel to completely crash.
> >
> > Any ideas??? Also Why do I get 2 vbok pop up boxes????
> >
> > Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As Boolean)
> >
> >
> > MsgBox "You should see something renamed!!", vbOK
> >
> > Sheet1.Name = "As of " & Format(Now(), "MM-DD-YYYY")
> >
> > ChDir "<new dir path>"
> > ActiveWorkbook.SaveAs _
> > "<MyFileName>" & Format(Now(), "yyyymmdd")
> >
> > End Sub
> >

 
Reply With Quote
 
=?Utf-8?B?SmltIFRob21saW5zb24=?=
Guest
Posts: n/a
 
      29th May 2007
Check out Chip's site. He covers events along with every other VBA ting under
the sun...

http://www.cpearson.com/excel/topic.htm
--
HTH...

Jim Thomlinson


"awrex" wrote:

> THANK YOU!!!!!
> Works great. Would you happen to know of web reference that I can look at
> regarding this.
>
>
> "Jim Thomlinson" wrote:
>
> > Your save as is calling a save which is going to be an issue. You need to
> > cancel the pending save make your changes disable events, save the book and
> > then re enable... something like this...
> >
> > Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As Boolean)
> > On error goto ErrorHandler
> > Application.enableevents = false
> > cancel = true
> > MsgBox "You should see something renamed!!", vbOK
> >
> > Sheet1.Name = "As of " & Format(Now(), "MM-DD-YYYY")
> >
> > ChDir "<new dir path>"
> > ActiveWorkbook.SaveAs _
> > "<MyFileName>" & Format(Now(), "yyyymmdd")
> > ErrorHandler:
> > Application.enableevents = true
> > End Sub
> > --
> > HTH...
> >
> > Jim Thomlinson
> >
> >
> > "awrex" wrote:
> >
> > > Ok I had posted a question about some code (Subject: Code issue -
> > > before_save() - Filename with date stamp - worksheet), to which I got it to
> > > work but now it is causing my Excel to completely crash.
> > >
> > > Any ideas??? Also Why do I get 2 vbok pop up boxes????
> > >
> > > Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As Boolean)
> > >
> > >
> > > MsgBox "You should see something renamed!!", vbOK
> > >
> > > Sheet1.Name = "As of " & Format(Now(), "MM-DD-YYYY")
> > >
> > > ChDir "<new dir path>"
> > > ActiveWorkbook.SaveAs _
> > > "<MyFileName>" & Format(Now(), "yyyymmdd")
> > >
> > > End Sub
> > >

 
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
BeforeSave code that appends date - THANK YOU!!!! =?Utf-8?B?YXdyZXg=?= Microsoft Excel Programming 0 31st May 2007 12:01 AM
BeforeSave event fired but not working when triggered by SaveAs. =?Utf-8?B?QW5kZXJz?= Microsoft Excel Programming 3 6th Oct 2006 04:58 PM
Event (BeforeSave) - How to test VBA code? Dave P. can you hear me now? EagleOne Microsoft Excel Misc 3 14th Sep 2006 07:46 PM
BeforeSave, Screenupdating = False, Why is it not working Claus Microsoft Excel Discussion 9 5th Jul 2005 12:36 PM
Code Problem in BeforeSave Event =?Utf-8?B?S2lyayBQLg==?= Microsoft Excel Programming 3 23rd Feb 2005 10:08 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 04:02 AM.