#1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3
Default File SaveAS

Hello,

I'm rather new to Excel coding so forgive me if this question sounds naive.

I'm trying to find a property that that I can use in the Workbook_BeforeSave
event in order to identify whether the user is trying to overwrite a specific
file on disk (by using the File SaveAs command), so that I can inform them of
this and cancel the Save event.

Thanks in advance for any assistance.
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,290
Default File SaveAS

Excel automatically displays a message if a file is being overwritten
unless your code suppresses the display of alert messages.
--
Jim Cone
San Francisco, USA
http://www.realezsites.com/bus/primitivesoftware


"Mickmoo"

wrote in message
Hello,
I'm rather new to Excel coding so forgive me if this question sounds naive.
I'm trying to find a property that that I can use in the Workbook_BeforeSave
event in order to identify whether the user is trying to overwrite a specific
file on disk (by using the File SaveAs command), so that I can inform them of
this and cancel the Save event.
Thanks in advance for any assistance.
  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3
Default File SaveAS

Thanks Jim,

I follow the point about Excel displaying a message enabling the user to
cancel the operation (assuming displayalerts isn't suppressed) , but they
still have the ability to click Yes and overwrite the file.
What I need to be able to do is trap the new filename before the save
operation operation occurs, compare it with the name of the file I do not
wish overwritten, and then cancel the save operation if the two names match.

Can this be done?

Many thanks


"Jim Cone" wrote:

Excel automatically displays a message if a file is being overwritten
unless your code suppresses the display of alert messages.
--
Jim Cone
San Francisco, USA
http://www.realezsites.com/bus/primitivesoftware


"Mickmoo"

wrote in message
Hello,
I'm rather new to Excel coding so forgive me if this question sounds naive.
I'm trying to find a property that that I can use in the Workbook_BeforeSave
event in order to identify whether the user is trying to overwrite a specific
file on disk (by using the File SaveAs command), so that I can inform them of
this and cancel the Save event.
Thanks in advance for any assistance.

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,290
Default File SaveAS

Code goes in the ThisWorkbook module...

Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, _
Cancel As Boolean)
On Error GoTo PrintingOver
Application.EnableEvents = False
Dim varResponse As Variant

varResponse = Application.GetSaveAsFilename( _
FileFilter:="Microsoft Excel Workbook (*.xls), *.xls")

If varResponse = False Then
'do nothing except exit
ElseIf varResponse = Me.FullName Then
MsgBox "Please save under a different name. "
Else
ThisWorkbook.SaveAs varResponse
End If

PrintingOver:
Application.EnableEvents = True
Cancel = True
End Sub
-----------
Jim Cone
San Francisco, USA
http://www.officeletter.com/blink/specialsort.html.



"Mickmoo"
wrote in message
Thanks Jim,
I follow the point about Excel displaying a message enabling the user to
cancel the operation (assuming displayalerts isn't suppressed) , but they
still have the ability to click Yes and overwrite the file.
What I need to be able to do is trap the new filename before the save
operation operation occurs, compare it with the name of the file I do not
wish overwritten, and then cancel the save operation if the two names match.
Can this be done?
Many thanks


"Jim Cone" wrote:
Excel automatically displays a message if a file is being overwritten
unless your code suppresses the display of alert messages.
--
Jim Cone
San Francisco, USA
http://www.realezsites.com/bus/primitivesoftware


"Mickmoo"

wrote in message
Hello,
I'm rather new to Excel coding so forgive me if this question sounds naive.
I'm trying to find a property that that I can use in the Workbook_BeforeSave
event in order to identify whether the user is trying to overwrite a specific
file on disk (by using the File SaveAs command), so that I can inform them of
this and cancel the Save event.
Thanks in advance for any assistance.

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3
Default File SaveAS

Jim,

That did the trick.

I never thought of calling the GetFileNameAs method and capturing the user's
response. We live and learn!

You're a star and a credit to the community.

Many thanks

"Jim Cone" wrote:

Code goes in the ThisWorkbook module...

Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, _
Cancel As Boolean)
On Error GoTo PrintingOver
Application.EnableEvents = False
Dim varResponse As Variant

varResponse = Application.GetSaveAsFilename( _
FileFilter:="Microsoft Excel Workbook (*.xls), *.xls")

If varResponse = False Then
'do nothing except exit
ElseIf varResponse = Me.FullName Then
MsgBox "Please save under a different name. "
Else
ThisWorkbook.SaveAs varResponse
End If

PrintingOver:
Application.EnableEvents = True
Cancel = True
End Sub
-----------
Jim Cone
San Francisco, USA
http://www.officeletter.com/blink/specialsort.html.



"Mickmoo"
wrote in message
Thanks Jim,
I follow the point about Excel displaying a message enabling the user to
cancel the operation (assuming displayalerts isn't suppressed) , but they
still have the ability to click Yes and overwrite the file.
What I need to be able to do is trap the new filename before the save
operation operation occurs, compare it with the name of the file I do not
wish overwritten, and then cancel the save operation if the two names match.
Can this be done?
Many thanks


"Jim Cone" wrote:
Excel automatically displays a message if a file is being overwritten
unless your code suppresses the display of alert messages.
--
Jim Cone
San Francisco, USA
http://www.realezsites.com/bus/primitivesoftware


"Mickmoo"

wrote in message
Hello,
I'm rather new to Excel coding so forgive me if this question sounds naive.
I'm trying to find a property that that I can use in the Workbook_BeforeSave
event in order to identify whether the user is trying to overwrite a specific
file on disk (by using the File SaveAs command), so that I can inform them of
this and cancel the Save event.
Thanks in advance for any assistance.




  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,290
Default File SaveAS

You are welcome, the feedback is appreciated.
Jim Cone


"Mickmoo"
wrote in message
Jim,
That did the trick.
I never thought of calling the GetFileNameAs method and capturing the user's
response. We live and learn!
You're a star and a credit to the community.
Many thanks

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
Confused here Prevent Saving File - but allow ONLY File SAVEAS Met JMay Excel Discussion (Misc queries) 2 June 17th 07 04:37 PM
saveas CSV file stevekirk Excel Discussion (Misc queries) 0 August 10th 06 01:11 PM
How can I make File-Save , File-SaveAs Menu disabled? Zoo Excel Programming 4 June 5th 06 06:58 AM
Saveas csv file Fib Excel Programming 10 May 9th 06 03:21 PM
File SaveAs FinChase Excel Programming 1 March 7th 06 01:41 AM


All times are GMT +1. The time now is 03:43 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"