Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 54
Default Need help with BeforeSave event

Hi,

I have code in the BeforeSave to 'suggest' a filename to save as but the
user needs to be able to change the 'suggestion' before saving. I'm using
Application.GetSaveAsFilename to suggest the filename. When
ThisWorkbook.SaveAs SaveAsFileName is executed, it fires the BeforeSave event
again. Is there anyway a better way to do what I'm attempting here?


If SaveAsUI = True Then
' displays SaveAs dialog box with default filename. Returns
SaveAsFileName
SaveAsFileName = Application.GetSaveAsFilename(PMFileName, "Microsoft
Office Excel Workbook (*.xls), *.xls")
' if user clicked Cancel then SaveAsFileName = False
If SaveAsFileName = "False" Then
Cancel = True
Exit Sub
Else
ThisWorkbook.SaveAs SaveAsFileName
Cancel = True
End If
End If
--
Thanks in advance!
Chuck M.
  #2   Report Post  
Posted to microsoft.public.excel.programming
Jay Jay is offline
external usenet poster
 
Posts: 671
Default Need help with BeforeSave event

Temporarily disable events with "Application.EnableEvents=False". Then reset
to True as follows:

If SaveAsFileName = "False" Then
Cancel = True '<<<===I think this is unnecessary; suggest delete
(but test)
Exit Sub
Else
Application.EnableEvents = False
ThisWorkbook.SaveAs SaveAsFileName
Application.EnableEvents = True
Cancel = True '<<<===I think this is unnecessary; suggest delete
(but test)
End If
End If

--
Jay


"Chuck M" wrote:

Hi,

I have code in the BeforeSave to 'suggest' a filename to save as but the
user needs to be able to change the 'suggestion' before saving. I'm using
Application.GetSaveAsFilename to suggest the filename. When
ThisWorkbook.SaveAs SaveAsFileName is executed, it fires the BeforeSave event
again. Is there anyway a better way to do what I'm attempting here?


If SaveAsUI = True Then
' displays SaveAs dialog box with default filename. Returns
SaveAsFileName
SaveAsFileName = Application.GetSaveAsFilename(PMFileName, "Microsoft
Office Excel Workbook (*.xls), *.xls")
' if user clicked Cancel then SaveAsFileName = False
If SaveAsFileName = "False" Then
Cancel = True
Exit Sub
Else
ThisWorkbook.SaveAs SaveAsFileName
Cancel = True
End If
End If
--
Thanks in advance!
Chuck M.

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Need help with BeforeSave event

Cancel = true
means to not perform the action that triggered the BeforeSave Event, so it
is certainly necessary.

--
Regards,
Tom Ogilvy

"Jay" wrote in message
...
Temporarily disable events with "Application.EnableEvents=False". Then
reset
to True as follows:

If SaveAsFileName = "False" Then
Cancel = True '<<<===I think this is unnecessary; suggest delete
(but test)
Exit Sub
Else
Application.EnableEvents = False
ThisWorkbook.SaveAs SaveAsFileName
Application.EnableEvents = True
Cancel = True '<<<===I think this is unnecessary; suggest delete
(but test)
End If
End If

--
Jay


"Chuck M" wrote:

Hi,

I have code in the BeforeSave to 'suggest' a filename to save as but the
user needs to be able to change the 'suggestion' before saving. I'm using
Application.GetSaveAsFilename to suggest the filename. When
ThisWorkbook.SaveAs SaveAsFileName is executed, it fires the BeforeSave
event
again. Is there anyway a better way to do what I'm attempting here?


If SaveAsUI = True Then
' displays SaveAs dialog box with default filename. Returns
SaveAsFileName
SaveAsFileName = Application.GetSaveAsFilename(PMFileName,
"Microsoft
Office Excel Workbook (*.xls), *.xls")
' if user clicked Cancel then SaveAsFileName = False
If SaveAsFileName = "False" Then
Cancel = True
Exit Sub
Else
ThisWorkbook.SaveAs SaveAsFileName
Cancel = True
End If
End If
--
Thanks in advance!
Chuck M.



  #4   Report Post  
Posted to microsoft.public.excel.programming
Jay Jay is offline
external usenet poster
 
Posts: 671
Default Need help with BeforeSave event

Agreed; don't delete Cancel=True. Thanks Tom.
--
Jay


"Tom Ogilvy" wrote:

Cancel = true
means to not perform the action that triggered the BeforeSave Event, so it
is certainly necessary.

--
Regards,
Tom Ogilvy

"Jay" wrote in message
...
Temporarily disable events with "Application.EnableEvents=False". Then
reset
to True as follows:

If SaveAsFileName = "False" Then
Cancel = True '<<<===I think this is unnecessary; suggest delete
(but test)
Exit Sub
Else
Application.EnableEvents = False
ThisWorkbook.SaveAs SaveAsFileName
Application.EnableEvents = True
Cancel = True '<<<===I think this is unnecessary; suggest delete
(but test)
End If
End If

--
Jay


"Chuck M" wrote:

Hi,

I have code in the BeforeSave to 'suggest' a filename to save as but the
user needs to be able to change the 'suggestion' before saving. I'm using
Application.GetSaveAsFilename to suggest the filename. When
ThisWorkbook.SaveAs SaveAsFileName is executed, it fires the BeforeSave
event
again. Is there anyway a better way to do what I'm attempting here?


If SaveAsUI = True Then
' displays SaveAs dialog box with default filename. Returns
SaveAsFileName
SaveAsFileName = Application.GetSaveAsFilename(PMFileName,
"Microsoft
Office Excel Workbook (*.xls), *.xls")
' if user clicked Cancel then SaveAsFileName = False
If SaveAsFileName = "False" Then
Cancel = True
Exit Sub
Else
ThisWorkbook.SaveAs SaveAsFileName
Cancel = True
End If
End If
--
Thanks in advance!
Chuck M.




  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 54
Default Need help with BeforeSave event

Thanks Jay and Tom. This works perfectly!
--
Thanks.
Chuck M.


"Jay" wrote:

Agreed; don't delete Cancel=True. Thanks Tom.
--
Jay


"Tom Ogilvy" wrote:

Cancel = true
means to not perform the action that triggered the BeforeSave Event, so it
is certainly necessary.

--
Regards,
Tom Ogilvy

"Jay" wrote in message
...
Temporarily disable events with "Application.EnableEvents=False". Then
reset
to True as follows:

If SaveAsFileName = "False" Then
Cancel = True '<<<===I think this is unnecessary; suggest delete
(but test)
Exit Sub
Else
Application.EnableEvents = False
ThisWorkbook.SaveAs SaveAsFileName
Application.EnableEvents = True
Cancel = True '<<<===I think this is unnecessary; suggest delete
(but test)
End If
End If

--
Jay


"Chuck M" wrote:

Hi,

I have code in the BeforeSave to 'suggest' a filename to save as but the
user needs to be able to change the 'suggestion' before saving. I'm using
Application.GetSaveAsFilename to suggest the filename. When
ThisWorkbook.SaveAs SaveAsFileName is executed, it fires the BeforeSave
event
again. Is there anyway a better way to do what I'm attempting here?


If SaveAsUI = True Then
' displays SaveAs dialog box with default filename. Returns
SaveAsFileName
SaveAsFileName = Application.GetSaveAsFilename(PMFileName,
"Microsoft
Office Excel Workbook (*.xls), *.xls")
' if user clicked Cancel then SaveAsFileName = False
If SaveAsFileName = "False" Then
Cancel = True
Exit Sub
Else
ThisWorkbook.SaveAs SaveAsFileName
Cancel = True
End If
End If
--
Thanks in advance!
Chuck M.




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
Trying to run macro on the BeforeSave event dmagoo22 Excel Programming 3 July 5th 06 09:38 PM
BeforeSave Event Question Andibevan[_4_] Excel Programming 0 August 11th 05 11:35 AM
BeforeSave event Carl Bowman Excel Discussion (Misc queries) 4 February 6th 05 12:28 PM
BeforeSave event j23 Excel Programming 0 April 6th 04 11:15 AM
BeforeSave workbook event Cindy Excel Programming 15 February 10th 04 04:28 PM


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

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

About Us

"It's about Microsoft Excel"