Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default 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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,646
Default 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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default 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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default 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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,646
Default 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
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
Excell2003 (SP-1) File > Save and File > Save As.. grayed out Joe Murphy Excel Discussion (Misc queries) 0 March 9th 05 10:00 PM
Save Excel file - prompts to save - no Volitile functions used POWER CERTS Excel Worksheet Functions 2 November 1st 04 09:27 PM
Excel marcos firing on file save as but not file save Andy Excel Programming 1 August 3rd 04 10:34 AM
Save File to Another Directory, but not change Users File Save location Mike Knight Excel Programming 1 May 28th 04 09:06 PM
Save As - Multiple Sheets fails to save as text file Ravee Srinivasan Excel Programming 2 November 10th 03 04:05 PM


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