Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 92
Default How check for No/Cancel Button when SaveAs and file already exists?

Hello -

I have a quick question: I use the ThisWorkbook.SaveAs function to
save a file but if the file already exists, Excel shows a warning. The
problem is that if I say either No or Cancel, there is an exception
thrown. How can I catch the result of that MsgBox()?

Thanks!
Joe

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,272
Default How check for No/Cancel Button when SaveAs and file already exists?

Joe,

What are you tryin g to do, not save it if it already exists? If so, try
trapping it, and don't save if so

Function FileExists(sFilename As String) As Boolean
FileExists = Dir(sFilename) < ""
End Function



--

HTH

RP
(remove nothere from the email address if mailing direct)


"Joe HM" wrote in message
oups.com...
Hello -

I have a quick question: I use the ThisWorkbook.SaveAs function to
save a file but if the file already exists, Excel shows a warning. The
problem is that if I say either No or Cancel, there is an exception
thrown. How can I catch the result of that MsgBox()?

Thanks!
Joe



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 92
Default How check for No/Cancel Button when SaveAs and file already exists?

Hello -

I get an error if I press either No or Cancel in the prompt that Excel
will show if the file already exists:
Run-time error '1004'
Method 'SaveAs' of object '_Workbook' failed.
Is there a way to catch that?

Thanks,
Joe

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,272
Default How check for No/Cancel Button when SaveAs and file already exists?

Yeah, as I said

If FileExists("myfilename") Then
'do nothing
Else
Activeworkbook.SaveAs Filename:="myfilename"
End If

--

HTH

RP
(remove nothere from the email address if mailing direct)


"Joe HM" wrote in message
oups.com...
Hello -

I get an error if I press either No or Cancel in the prompt that Excel
will show if the file already exists:
Run-time error '1004'
Method 'SaveAs' of object '_Workbook' failed.
Is there a way to catch that?

Thanks,
Joe



  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 92
Default How check for No/Cancel Button when SaveAs and file already exists?

Hello -

I get an error if I press either No or Cancel in the prompt that Excel
will show if the file already exists:
Run-time error '1004'
Method 'SaveAs' of object '_Workbook' failed.
Is there a way to catch that?

Thanks,
Joe



  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 92
Default How check for No/Cancel Button when SaveAs and file already exists?

D'oh ... got you!

I just thought that the SaveAs function would return some status.

Thanks!
Joe

  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,272
Default How check for No/Cancel Button when SaveAs and file already exists?

You can also do

On Error Resume Next
ActiveWorkbook.SaveAs Filename:="C:\Mytest\Volker1.xls"
On Error GoTo 0

which will give you the prompt that you can No/Cancel, but I prefer nthe
first method

--

HTH

RP
(remove nothere from the email address if mailing direct)


"Joe HM" wrote in message
oups.com...
D'oh ... got you!

I just thought that the SaveAs function would return some status.

Thanks!
Joe



  #8   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 92
Default How check for No/Cancel Button when SaveAs and file already exists?

Great! Thanks so much!

Joe

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
Check if file exists Jon Excel Discussion (Misc queries) 14 October 4th 07 04:57 PM
Saveas where file already exists faberk Excel Programming 4 March 29th 05 12:25 AM
SaveAs command when a file already exists? debartsa Excel Programming 2 January 5th 04 04:12 PM
check if a file exists / is open Mark Kubicki Excel Programming 1 December 4th 03 05:56 PM
How do I check if a user clicked the Print Cancel button joanne Excel Programming 0 September 5th 03 08:24 AM


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