Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 8
Default Result code for SaveAs

Is there a result code for the SaveAs method that I could use to
conditionally direct the execution of this code around the block of code that
starts "If Err.Number..." if the user elects not to save the file?

Here is the code:

If fs.FileExists(strPathName) Then
On Error Resume Next
ActiveWorkbook.SaveAs Filename:=strPathName, _
FileFormat:=xlNormal, _
ReadOnlyRecommended:=False, _
CreateBackup:=False
If Err.Number = 1004 & Left(strFileName, 2) < "ts" Then
Msg = "Save aborted. This timesheet will now close. Open " _
& strFileName & " directly in " & strSaveDirectory & "."
MsgBox Msg, vbOKOnly, "Error"
ActiveWorkbook.Close SaveChanges:=False
End If
On Error GoTo 0
Err.Clear

Thank you.

John Wirt
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 857
Default Result code for SaveAs

I don't think SaveAs returns any value. How about doing it like this:

If fs.FileExists(strPathName) Then
If vbYes = MsgBox("Overwrite existing file?", vbYesNo) Then
Application.DisplayAlerts = False
ActiveWorkbook.SaveAs Filename:=strPathName, _
FileFormat:=xlNormal, _
ReadOnlyRecommended:=False, _
CreateBackup:=False
Application.DisplayAlerts = False
Else
Msg = "Save aborted. This timesheet will now close. Open " _
& strFileName & " directly in " & strSaveDirectory & "."
MsgBox Msg, vbOKOnly, "Error"
ActiveWorkbook.Close SaveChanges:=False
End If
End If


--
Hope that helps.

Vergel Adriano


"JWirt" wrote:

Is there a result code for the SaveAs method that I could use to
conditionally direct the execution of this code around the block of code that
starts "If Err.Number..." if the user elects not to save the file?

Here is the code:

If fs.FileExists(strPathName) Then
On Error Resume Next
ActiveWorkbook.SaveAs Filename:=strPathName, _
FileFormat:=xlNormal, _
ReadOnlyRecommended:=False, _
CreateBackup:=False
If Err.Number = 1004 & Left(strFileName, 2) < "ts" Then
Msg = "Save aborted. This timesheet will now close. Open " _
& strFileName & " directly in " & strSaveDirectory & "."
MsgBox Msg, vbOKOnly, "Error"
ActiveWorkbook.Close SaveChanges:=False
End If
On Error GoTo 0
Err.Clear

Thank you.

John Wirt

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 8
Default Result code for SaveAs

YEP, you've got the problem and it looks like the solution. Thanks. Joh

"Vergel Adriano" wrote:

I don't think SaveAs returns any value. How about doing it like this:

If fs.FileExists(strPathName) Then
If vbYes = MsgBox("Overwrite existing file?", vbYesNo) Then
Application.DisplayAlerts = False
ActiveWorkbook.SaveAs Filename:=strPathName, _
FileFormat:=xlNormal, _
ReadOnlyRecommended:=False, _
CreateBackup:=False
Application.DisplayAlerts = False
Else
Msg = "Save aborted. This timesheet will now close. Open " _
& strFileName & " directly in " & strSaveDirectory & "."
MsgBox Msg, vbOKOnly, "Error"
ActiveWorkbook.Close SaveChanges:=False
End If
End If


--
Hope that helps.

Vergel Adriano


"JWirt" wrote:

Is there a result code for the SaveAs method that I could use to
conditionally direct the execution of this code around the block of code that
starts "If Err.Number..." if the user elects not to save the file?

Here is the code:

If fs.FileExists(strPathName) Then
On Error Resume Next
ActiveWorkbook.SaveAs Filename:=strPathName, _
FileFormat:=xlNormal, _
ReadOnlyRecommended:=False, _
CreateBackup:=False
If Err.Number = 1004 & Left(strFileName, 2) < "ts" Then
Msg = "Save aborted. This timesheet will now close. Open " _
& strFileName & " directly in " & strSaveDirectory & "."
MsgBox Msg, vbOKOnly, "Error"
ActiveWorkbook.Close SaveChanges:=False
End If
On Error GoTo 0
Err.Clear

Thank you.

John Wirt

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 8
Default Result code for SaveAs


Except, I think the second Application.DisplayAlerts should be True.
John

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 857
Default Result code for SaveAs

Ahh... Copy-paste got me again. You're right. The second one should be true..


--
Hope that helps.

Vergel Adriano


"JWirt" wrote:


Except, I think the second Application.DisplayAlerts should be True.
John

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
How to enter a zip code & get a result of which area it is Hatoof Excel Discussion (Misc queries) 1 September 18th 09 11:18 AM
SaveAs Code Ronbo Excel Programming 2 January 13th 06 03:49 PM
SaveAs Result? Shawn Shuler Excel Programming 4 August 10th 04 04:10 PM
SAveAs executes combobox code Alan Lyall Excel Programming 3 June 9th 04 12:52 AM
URGENT - Need date format for SaveAs code Ed[_9_] Excel Programming 4 November 6th 03 08:48 PM


All times are GMT +1. The time now is 12:34 PM.

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"