Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.excel.programming
|
|||
|
|||
Save file queries
Hi, I have this line of code (Y is a string) ActiveWorkbook.SaveAs Filename:=Y when there are a same file name "Y" exist in the same location, but i don't want to overwrite the file, what code that need to add, in order to ask the user to enter another file name instead o overwrite the file? Regards yl chuah : -- ylchua ----------------------------------------------------------------------- ylchuah's Profile: http://www.excelforum.com/member.php...fo&userid=2534 View this thread: http://www.excelforum.com/showthread.php?threadid=40037 |
#2
Posted to microsoft.public.excel.programming
|
|||
|
|||
Save file queries
Do While FileExists(Y) Y = InputBox(Y & " does exist!" & Chr(10) & "Enter new filename!") Loop ActiveWorkbook.SaveAs Filename:=Y Public Function FileExists(fname As String) As Boolean FileExists = IIf(Dir(fname) < "", True, False) End Function Regards, Stefi ylchuah ezt *rta: Hi, I have this line of code (Y is a string) ActiveWorkbook.SaveAs Filename:=Y when there are a same file name "Y" exist in the same location, but i don't want to overwrite the file, what code that need to add, in order to ask the user to enter another file name instead of overwrite the file? Regards yl chuah :( -- ylchuah ------------------------------------------------------------------------ ylchuah's Profile: http://www.excelforum.com/member.php...o&userid=25341 View this thread: http://www.excelforum.com/showthread...hreadid=400373 |
#3
Posted to microsoft.public.excel.programming
|
|||
|
|||
Save file queries
do
y = application.GetSaveAsFileName() if dir(y) < "" then msgbox "File exists, please provide another name rather than" _ & vbCrLf & vbCrLf & y else exit do end if Loop while True ActiveWorkbook.SaveAs Filename:=Y -- Regards, Tom Ogilvy "ylchuah" wrote in message ... Hi, I have this line of code (Y is a string) ActiveWorkbook.SaveAs Filename:=Y when there are a same file name "Y" exist in the same location, but i don't want to overwrite the file, what code that need to add, in order to ask the user to enter another file name instead of overwrite the file? Regards yl chuah :( -- ylchuah ------------------------------------------------------------------------ ylchuah's Profile: http://www.excelforum.com/member.php...o&userid=25341 View this thread: http://www.excelforum.com/showthread...hreadid=400373 |
#4
Posted to microsoft.public.excel.programming
|
|||
|
|||
Save file queries
Hi, Stefi, Thanks for your help. But i have try this code, error occurs. (Expected End Sub) Actually i don't know how to use the public function. in my exisitng programme, right after this line 'ActiveWorkbook.SaveAs Filename:=PCLname' will have a window pop out say "A file named "Y" already exists in this location. Do you want to replace it?" when i click "No" or "Cancel" run-rime error '1004' happen "Method 'SaveAs' of object'_Workbook' failed So, any idea? Regards yl chuah Stefi Wrote: [color=blue] Do While FileExists(Y) Y = InputBox(Y & " does exist!" & Chr(10) & "Enter new filename!") Loop ActiveWorkbook.SaveAs Filename:=Y Public Function FileExists(fname As String) As Boolean FileExists = IIf(Dir(fname) < "", True, False) End Function Regards, Stefi ylchuah ezt *rta: -- ylchuah ------------------------------------------------------------------------ ylchuah's Profile: http://www.excelforum.com/member.php...o&userid=25341 View this thread: http://www.excelforum.com/showthread...hreadid=400373 |
#5
Posted to microsoft.public.excel.programming
|
|||
|
|||
Save file queries
Hi ylchuah,
I suppose the problem comes from wrongly inserting my piece of code into your sub, but I have to see the whole sub to find the error. But i have try this code, error occurs. (Expected End Sub) I suppose the problem comes from wrongly inserting my piece of code into your sub, but I have to see the whole sub to find the error. Actually i don't know how to use the public function. Just copy it after your sub. Or use Tom's piece of code, it does the same without UDF. in my exisitng programme, right after this line 'ActiveWorkbook.SaveAs Filename:=PCLname' will have a window pop out say "A file named "Y" already exists in this location. Do you want to replace it?" when i click "No" or "Cancel" run-rime error '1004' happen "Method 'SaveAs' of object'_Workbook' failed PCLname is a variable that contains the string "Y". If you already have this file, and if you reply No, control go back to the same statement 'ActiveWorkbook.SaveAs Filename:=PCLname' and gives an error, because VB cannot execute it without your permission. To go around it use the above procedure, or - if you do not want to ask a new filename, do this: On Error Resume Next ActiveWorkbook.SaveAs Filename:=PCLname On Error GoTo 0 Regards, Stefi [color=blue] So, any idea? Regards yl chuah Stefi Wrote: Do While FileExists(Y) Y = InputBox(Y & " does exist!" & Chr(10) & "Enter new filename!") Loop ActiveWorkbook.SaveAs Filename:=Y Public Function FileExists(fname As String) As Boolean FileExists = IIf(Dir(fname) < "", True, False) End Function Regards, Stefi âžylchuahâ ezt Ã*rta: -- ylchuah ------------------------------------------------------------------------ ylchuah's Profile: http://www.excelforum.com/member.php...o&userid=25341 View this thread: http://www.excelforum.com/showthread...hreadid=400373 |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
Excell2003 (SP-1) File > Save and File > Save As.. grayed out | Excel Discussion (Misc queries) | |||
Save Excel file - prompts to save - no Volitile functions used | Excel Worksheet Functions | |||
Excel marcos firing on file save as but not file save | Excel Programming | |||
Save File to Another Directory, but not change Users File Save location | Excel Programming | |||
Save As - Multiple Sheets fails to save as text file | Excel Programming |