Home |
Search |
Today's Posts |
|
#1
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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 |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
Lost "File Menu" - now it's "Edit / View / Insert.." but no "F | Excel Discussion (Misc queries) | |||
Excel "Save as" dialog - when file already exists | Excel Programming | |||
If the file exists "Yes should appear" | Excel Programming | |||
Macro help - "Save As" when a file already exists | Excel Programming | |||
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?" | Excel Programming |