#1   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 135
Default SaveAs method error

I have noticed a problem with the SaveAs method I am using. Here is the code:
Dim fSaveName as Variant
Do
fSaveName = Application.GetSaveAsFilename
Loop Until fSaveName < False
ThisWorkbook.SaveAs fSaveName

If the file name/location I choose in the GetSaveAsFilename dialog already
exists, I am asked if I want to replace it.
Clicking Yes replaces the file as expected, but clicking No or Cancel leads
to an error: "Method 'SaveAs' of object '_Workbook' failed"

Is there a way to handle this situation?


  #2   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 8,520
Default SaveAs method error

Try the below..

Dim fSaveName As Variant
Do
fSaveName = Application.GetSaveAsFilename
Loop Until fSaveName < False
If Dir(fSaveName, vbNormal) < "" Then
If MsgBox("File already exists, Overwrite ?", vbYesNo + vbDefaultButton2) _
< vbYes Then Exit Sub
End If
Application.DisplayAlerts = True
ThisWorkbook.SaveAs fSaveName
Application.DisplayAlerts = False

If this post helps click Yes
---------------
Jacob Skaria


"Horatio J. Bilge, Jr." wrote:

I have noticed a problem with the SaveAs method I am using. Here is the code:
Dim fSaveName as Variant
Do
fSaveName = Application.GetSaveAsFilename
Loop Until fSaveName < False
ThisWorkbook.SaveAs fSaveName

If the file name/location I choose in the GetSaveAsFilename dialog already
exists, I am asked if I want to replace it.
Clicking Yes replaces the file as expected, but clicking No or Cancel leads
to an error: "Method 'SaveAs' of object '_Workbook' failed"

Is there a way to handle this situation?


  #3   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 8,520
Default SaveAs method error

Correction....for the last line.Try the below

Dim fSaveName As Variant
Do
fSaveName = Application.GetSaveAsFilename
Loop Until fSaveName < False
If Dir(fSaveName, vbNormal) < "" Then
If MsgBox("File already exists, Overwrite ?", vbYesNo + vbDefaultButton2) _
< vbYes Then Exit Sub
End If
Application.DisplayAlerts = False
ThisWorkbook.SaveAs fSaveName
Application.DisplayAlerts = True


If this post helps click Yes
---------------
Jacob Skaria


"Jacob Skaria" wrote:

Try the below..

Dim fSaveName As Variant
Do
fSaveName = Application.GetSaveAsFilename
Loop Until fSaveName < False
If Dir(fSaveName, vbNormal) < "" Then
If MsgBox("File already exists, Overwrite ?", vbYesNo + vbDefaultButton2) _
< vbYes Then Exit Sub
End If
Application.DisplayAlerts = True
ThisWorkbook.SaveAs fSaveName
Application.DisplayAlerts = False

If this post helps click Yes
---------------
Jacob Skaria


"Horatio J. Bilge, Jr." wrote:

I have noticed a problem with the SaveAs method I am using. Here is the code:
Dim fSaveName as Variant
Do
fSaveName = Application.GetSaveAsFilename
Loop Until fSaveName < False
ThisWorkbook.SaveAs fSaveName

If the file name/location I choose in the GetSaveAsFilename dialog already
exists, I am asked if I want to replace it.
Clicking Yes replaces the file as expected, but clicking No or Cancel leads
to an error: "Method 'SaveAs' of object '_Workbook' failed"

Is there a way to handle this situation?


  #4   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 135
Default SaveAs method error

Thank you! That works great. I had to add a second End If statement, and then
instead of exiting the sub, I sent it back to the GetSaveAsFilename loop:

Dim fSaveName As Variant
WhereToSave:
Do
fSaveName = Application.GetSaveAsFilename
Loop Until fSaveName < False
If Dir(fSaveName, vbNormal) < "" Then
If MsgBox("File already exists, Overwrite ?", vbYesNo + vbDefaultButton2) <
vbYes Then
GoTo WhereToSave
End If
End If
Application.DisplayAlerts = False
ThisWorkbook.SaveAs fSaveName
Application.DisplayAlerts = True

"Jacob Skaria" wrote:

Correction....for the last line.Try the below

Dim fSaveName As Variant
Do
fSaveName = Application.GetSaveAsFilename
Loop Until fSaveName < False
If Dir(fSaveName, vbNormal) < "" Then
If MsgBox("File already exists, Overwrite ?", vbYesNo + vbDefaultButton2) _
< vbYes Then Exit Sub
End If
Application.DisplayAlerts = False
ThisWorkbook.SaveAs fSaveName
Application.DisplayAlerts = True


If this post helps click Yes
---------------
Jacob Skaria


"Jacob Skaria" wrote:

Try the below..

Dim fSaveName As Variant
Do
fSaveName = Application.GetSaveAsFilename
Loop Until fSaveName < False
If Dir(fSaveName, vbNormal) < "" Then
If MsgBox("File already exists, Overwrite ?", vbYesNo + vbDefaultButton2) _
< vbYes Then Exit Sub
End If
Application.DisplayAlerts = True
ThisWorkbook.SaveAs fSaveName
Application.DisplayAlerts = False

If this post helps click Yes
---------------
Jacob Skaria


"Horatio J. Bilge, Jr." wrote:

I have noticed a problem with the SaveAs method I am using. Here is the code:
Dim fSaveName as Variant
Do
fSaveName = Application.GetSaveAsFilename
Loop Until fSaveName < False
ThisWorkbook.SaveAs fSaveName

If the file name/location I choose in the GetSaveAsFilename dialog already
exists, I am asked if I want to replace it.
Clicking Yes replaces the file as expected, but clicking No or Cancel leads
to an error: "Method 'SaveAs' of object '_Workbook' failed"

Is there a way to handle this situation?


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 do in perform trial and error method in excel? Raajesh Excel Worksheet Functions 1 October 3rd 08 10:32 AM
Paste method error in macro bwilk77 Excel Discussion (Misc queries) 2 October 25th 07 09:21 PM
PasteSpecial Method Error PW11111 Excel Discussion (Misc queries) 1 December 19th 06 01:24 PM
Error: method 'select' of object_worksheet' failed Carl Excel Discussion (Misc queries) 4 September 9th 06 08:52 PM
error message with saveas DJA Excel Discussion (Misc queries) 6 February 17th 05 06:03 PM


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