Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 92
Default After Save Event - Confirm

Thanks for all of your help. Just to confirm - by combining the suggestions
of your posts, is the below code the proper way to perform the After Save
Event? Thanks!

Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As
Boolean)
Cancel = True
'<Optional - this would be before save code
application.enableevents = false
ThisWorkbook.Save
application.enableevents = true
'<Optional - this would be after save code
End Sub


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default After Save Event - Confirm

That would be the basic approach.

--
Regards,
Tom Ogilvy

"Steph" wrote in message
...
Thanks for all of your help. Just to confirm - by combining the

suggestions
of your posts, is the below code the proper way to perform the After Save
Event? Thanks!

Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As
Boolean)
Cancel = True
'<Optional - this would be before save code
application.enableevents = false
ThisWorkbook.Save
application.enableevents = true
'<Optional - this would be after save code
End Sub




  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 92
Default After Save Event - Confirm

Thank you!

"Tom Ogilvy" wrote in message
...
That would be the basic approach.

--
Regards,
Tom Ogilvy

"Steph" wrote in message
...
Thanks for all of your help. Just to confirm - by combining the

suggestions
of your posts, is the below code the proper way to perform the After

Save
Event? Thanks!

Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As
Boolean)
Cancel = True
'<Optional - this would be before save code
application.enableevents = false
ThisWorkbook.Save
application.enableevents = true
'<Optional - this would be after save code
End Sub






  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 92
Default After Save Event - Confirm

What if the user selects Save As? Does that throw a monkey wrench in the
code?

"Tom Ogilvy" wrote in message
...
That would be the basic approach.

--
Regards,
Tom Ogilvy

"Steph" wrote in message
...
Thanks for all of your help. Just to confirm - by combining the

suggestions
of your posts, is the below code the proper way to perform the After

Save
Event? Thanks!

Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As
Boolean)
Cancel = True
'<Optional - this would be before save code
application.enableevents = false
ThisWorkbook.Save
application.enableevents = true
'<Optional - this would be after save code
End Sub






  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default After Save Event - Confirm

Yes. Because you are doing a SAVE

You can tell if the user is going to be offered a file name selection dialog
by checking


Dim fName as Variant
On Error goto ErrHandler

Cancel = True
if SaveAsUI then
fName = Applicaton.GetSaveAsFileName()
if fName = "False" then
exit sub
else
Application.EnableEvents = False
thisworkbook.SaveAs fName
Application.EnableEvents = True
end if
else
Application.EnableEvents = False
thisworkbook.Save
Application.EnableEvents = True
end if

ErrHandler:
Application.EnableEvents = True
end sub


--
Regards,
Tom Ogilvy


"Steph" wrote in message
...
What if the user selects Save As? Does that throw a monkey wrench in the
code?

"Tom Ogilvy" wrote in message
...
That would be the basic approach.

--
Regards,
Tom Ogilvy

"Steph" wrote in message
...
Thanks for all of your help. Just to confirm - by combining the

suggestions
of your posts, is the below code the proper way to perform the After

Save
Event? Thanks!

Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As
Boolean)
Cancel = True
'<Optional - this would be before save code
application.enableevents = false
ThisWorkbook.Save
application.enableevents = true
'<Optional - this would be after save code
End Sub










  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 92
Default After Save Event - Confirm

Perfect. Thanks so much Tom!!

"Tom Ogilvy" wrote in message
...
Yes. Because you are doing a SAVE

You can tell if the user is going to be offered a file name selection

dialog
by checking


Dim fName as Variant
On Error goto ErrHandler

Cancel = True
if SaveAsUI then
fName = Applicaton.GetSaveAsFileName()
if fName = "False" then
exit sub
else
Application.EnableEvents = False
thisworkbook.SaveAs fName
Application.EnableEvents = True
end if
else
Application.EnableEvents = False
thisworkbook.Save
Application.EnableEvents = True
end if

ErrHandler:
Application.EnableEvents = True
end sub


--
Regards,
Tom Ogilvy


"Steph" wrote in message
...
What if the user selects Save As? Does that throw a monkey wrench in

the
code?

"Tom Ogilvy" wrote in message
...
That would be the basic approach.

--
Regards,
Tom Ogilvy

"Steph" wrote in message
...
Thanks for all of your help. Just to confirm - by combining the
suggestions
of your posts, is the below code the proper way to perform the After

Save
Event? Thanks!

Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As
Boolean)
Cancel = True
'<Optional - this would be before save code
application.enableevents = false
ThisWorkbook.Save
application.enableevents = true
'<Optional - this would be after save code
End Sub










  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 92
Default After Save Event - Confirm

Tom,
I added a few msgbox statements and tested your code. The Save works great.
But when I select SaveAs, nothing happens. I don't get the prompt to enter
the file name, and the file is not saved at all. Any ideas? Here's what I
have:

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

Dim fName As Variant
On Error GoTo ErrHandler

Cancel = True
If SaveAsUI Then
fName = Applicaton.GetSaveAsFilename()
If fName = "False" Then
Exit Sub
Else
'<Optional - this would be before save code
MsgBox ("Before save")
Application.EnableEvents = False
ThisWorkbook.SaveAs fName
Application.EnableEvents = True
'<Optional - this would be after save code
MsgBox ("After save")
End If
Else
'<Optional - this would be before save code
MsgBox ("Before save")
Application.EnableEvents = False
ThisWorkbook.Save
Application.EnableEvents = True
'<Optional - this would be after save code
MsgBox ("After save")
End If

ErrHandler:
Application.EnableEvents = True

End Sub

"Tom Ogilvy" wrote in message
...
Yes. Because you are doing a SAVE

You can tell if the user is going to be offered a file name selection

dialog
by checking


Dim fName as Variant
On Error goto ErrHandler

Cancel = True
if SaveAsUI then
fName = Applicaton.GetSaveAsFileName()
if fName = "False" then
exit sub
else
Application.EnableEvents = False
thisworkbook.SaveAs fName
Application.EnableEvents = True
end if
else
Application.EnableEvents = False
thisworkbook.Save
Application.EnableEvents = True
end if

ErrHandler:
Application.EnableEvents = True
end sub


--
Regards,
Tom Ogilvy


"Steph" wrote in message
...
What if the user selects Save As? Does that throw a monkey wrench in

the
code?

"Tom Ogilvy" wrote in message
...
That would be the basic approach.

--
Regards,
Tom Ogilvy

"Steph" wrote in message
...
Thanks for all of your help. Just to confirm - by combining the
suggestions
of your posts, is the below code the proper way to perform the After

Save
Event? Thanks!

Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As
Boolean)
Cancel = True
'<Optional - this would be before save code
application.enableevents = false
ThisWorkbook.Save
application.enableevents = true
'<Optional - this would be after save code
End Sub










  #8   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default After Save Event - Confirm

Well one of use can't spell application < sheepish grin Guess it was me

fName = Applicaton.GetSaveAsFilename()

should be
fName = Application.GetSaveAsFilename()

Since there is an error handler in effect, it hides the error. Until you
get your code working you should comment out the

On error goto ErrHandler

line.

--
Regards,
Tom Ogilvy


"Steph" wrote in message
...
Tom,
I added a few msgbox statements and tested your code. The Save works

great.
But when I select SaveAs, nothing happens. I don't get the prompt to

enter
the file name, and the file is not saved at all. Any ideas? Here's what

I
have:

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

Dim fName As Variant
On Error GoTo ErrHandler

Cancel = True
If SaveAsUI Then
fName = Applicaton.GetSaveAsFilename()
If fName = "False" Then
Exit Sub
Else
'<Optional - this would be before save code
MsgBox ("Before save")
Application.EnableEvents = False
ThisWorkbook.SaveAs fName
Application.EnableEvents = True
'<Optional - this would be after save code
MsgBox ("After save")
End If
Else
'<Optional - this would be before save code
MsgBox ("Before save")
Application.EnableEvents = False
ThisWorkbook.Save
Application.EnableEvents = True
'<Optional - this would be after save code
MsgBox ("After save")
End If

ErrHandler:
Application.EnableEvents = True

End Sub

"Tom Ogilvy" wrote in message
...
Yes. Because you are doing a SAVE

You can tell if the user is going to be offered a file name selection

dialog
by checking


Dim fName as Variant
On Error goto ErrHandler

Cancel = True
if SaveAsUI then
fName = Applicaton.GetSaveAsFileName()
if fName = "False" then
exit sub
else
Application.EnableEvents = False
thisworkbook.SaveAs fName
Application.EnableEvents = True
end if
else
Application.EnableEvents = False
thisworkbook.Save
Application.EnableEvents = True
end if

ErrHandler:
Application.EnableEvents = True
end sub


--
Regards,
Tom Ogilvy


"Steph" wrote in message
...
What if the user selects Save As? Does that throw a monkey wrench in

the
code?

"Tom Ogilvy" wrote in message
...
That would be the basic approach.

--
Regards,
Tom Ogilvy

"Steph" wrote in message
...
Thanks for all of your help. Just to confirm - by combining the
suggestions
of your posts, is the below code the proper way to perform the

After
Save
Event? Thanks!

Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel

As
Boolean)
Cancel = True
'<Optional - this would be before save code
application.enableevents = false
ThisWorkbook.Save
application.enableevents = true
'<Optional - this would be after save code
End Sub












Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
Example After Save Event Steph[_6_] Excel Programming 4 October 27th 05 01:42 AM
After Save Event help Steph[_3_] Excel Programming 2 June 27th 05 07:00 PM
Before Save as Event needed [email protected] Excel Programming 4 April 20th 04 07:42 PM
save as event scrabtree23 Excel Programming 1 October 5th 03 10:14 PM
After save event Bart[_3_] Excel Programming 2 July 22nd 03 12:07 PM


All times are GMT +1. The time now is 03:35 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"