Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 15
Default If File exists Then NewFile="XYZ"

I have a macro that is used to copy a source file (dim srcfile as string) out
to a path (dim destpath as string).

user inputs the full source file path into a text box.
(srcfile=txt_source.text)

user input the destination path into a second text box.
(destpath=txt_destpath.text)

there is a command button (cmd_execute_copy) with associated code that
constructs a command line string using copy command with the user inputs
("cmd.exe /c copy " + srcfile + " " +destpath).

This all works just great. However, I would like to be able to construct an
IF statement that first checks to see if the same file name already exists in
the destination path. If it does, then I would like to be able to add ".bak"
to the end of the SRCFILE value and then continue the copy operation. I
guess the trick would be to first parse the SRCFILE string from the end
backwards to the first "\" that it runs into which should then indicate the
filename?

Here is my code so far:
Private Sub cmd_execute_copy_Click()
Dim srcfile As String
Dim destpath As String
Dim copystring As String
srcfile = txt_source.Text
destpath = txt_destpath.Text
copystring = "cmd.exe /c copy " + srcfile + " " + destpath
Shell (copystring), 1
end sub


Thanks in advance,

Pcola

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 533
Default If File exists Then NewFile="XYZ"

If Dir(srcfile) < "" Then
''Do whatever you want to the file name
End If

You might use FileCopy to avoid the kludgey Shell.

--
Jim
"PcolaITGuy" wrote in message
...
I have a macro that is used to copy a source file (dim srcfile as string)
out
to a path (dim destpath as string).

user inputs the full source file path into a text box.
(srcfile=txt_source.text)

user input the destination path into a second text box.
(destpath=txt_destpath.text)

there is a command button (cmd_execute_copy) with associated code that
constructs a command line string using copy command with the user inputs
("cmd.exe /c copy " + srcfile + " " +destpath).

This all works just great. However, I would like to be able to construct
an
IF statement that first checks to see if the same file name already exists
in
the destination path. If it does, then I would like to be able to add
".bak"
to the end of the SRCFILE value and then continue the copy operation. I
guess the trick would be to first parse the SRCFILE string from the end
backwards to the first "\" that it runs into which should then indicate
the
filename?

Here is my code so far:
Private Sub cmd_execute_copy_Click()
Dim srcfile As String
Dim destpath As String
Dim copystring As String
srcfile = txt_source.Text
destpath = txt_destpath.Text
copystring = "cmd.exe /c copy " + srcfile + " " + destpath
Shell (copystring), 1
end sub


Thanks in advance,

Pcola



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
Lost "File Menu" - now it's "Edit / View / Insert.." but no "F daves Excel Discussion (Misc queries) 3 April 24th 07 04:52 AM
Excel "Save as" dialog - when file already exists MattM[_2_] Excel Programming 3 July 19th 06 01:43 PM
If the file exists "Yes should appear" Sami82[_27_] Excel Programming 1 March 23rd 06 04:09 AM
Macro help - "Save As" when a file already exists Dave Excel Programming 1 May 18th 05 07:38 PM
within a macro how can I suppress the warning pop "A file named xxxx.xls already exists in this location. Do you want to replace it?" Pete McCosh Excel Programming 0 April 2nd 04 04:51 PM


All times are GMT +1. The time now is 10:29 PM.

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"