Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 400
Default Do you want to replace it?

From VB script, when executing the code:

ActiveWorkbook.SaveAs FileName:="C:\ZZ.XLS"

a dialogue comes up when the file exists already, requesting whether the
filename should be overwritten. How can I retrieve the option exercised by
the user: YES, NO, CANCEL?


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,718
Default Do you want to replace it?

What you should do is determine whether the file exists before the SaveAs
and ask the user what he wants to do:

Sub a()
Dim Resp As Integer
Dim FName As String
FName = "c:\abc.xls"
If Dir(FName) < "" Then
Resp = MsgBox(FName & " exists. Replace it?", vbYesNoCancel)
Select Case Resp
Case vbYes: MsgBox "User chose replace"
Case vbNo: MsgBox "User chose not to replace"
Case vbCancel: MsgBox "User chose cancel"
End Select
End If
End Sub

Of course in place of the message boxes in the Select you'd put the
appropriate actions, for Yes doing a SaveAs with Application.DisplayAlerts
set to False so the user is not prompted to replace the existing file.

--
Jim
"AA2e72E" wrote in message
...
| From VB script, when executing the code:
|
| ActiveWorkbook.SaveAs FileName:="C:\ZZ.XLS"
|
| a dialogue comes up when the file exists already, requesting whether the
| filename should be overwritten. How can I retrieve the option exercised by
| the user: YES, NO, CANCEL?
|
|


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
Find and Replace - Replace with Blank Space Studebaker Excel Discussion (Misc queries) 4 April 3rd 23 10:55 AM
Can I replace a ' at the beginning of a text cell using Replace Hilde Excel Discussion (Misc queries) 4 September 10th 07 06:22 PM
Replace dialog should put focus on "Find What" not "Replace With" Michael Williams Excel Discussion (Misc queries) 0 May 24th 06 12:45 PM
find and replace - replace data in rows to separated by commas msdker Excel Worksheet Functions 1 April 15th 06 01:00 AM
How can I use replace(alt+H) for mutiple items needing replace Gery Excel Worksheet Functions 1 June 15th 05 05:51 PM


All times are GMT +1. The time now is 11:03 AM.

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

About Us

"It's about Microsoft Excel"