Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.excel.programming
|
|||
|
|||
Moving Files and creating copies
FSO.MoveFile
With FSO.MoveFile, can you move the files and if they exist write them with a new name. If not how can I do that? Thanks |
#2
Posted to microsoft.public.excel.programming
|
|||
|
|||
Moving Files and creating copies
I would think that using SaveAs with the full path would allow you to move
and rename the files in one fell swoop. "Nils Titley" wrote: FSO.MoveFile With FSO.MoveFile, can you move the files and if they exist write them with a new name. If not how can I do that? Thanks |
#3
Posted to microsoft.public.excel.programming
|
|||
|
|||
Moving Files and creating copies
I would recommend using some addition to the filename. I typically use
something extra like date and time information added to the original filename to avoid overwriting previous versions of the same file. If you need some examples, let me know. Mark "Nils Titley" wrote in message ... FSO.MoveFile With FSO.MoveFile, can you move the files and if they exist write them with a new name. If not how can I do that? Thanks |
#4
Posted to microsoft.public.excel.programming
|
|||
|
|||
Moving Files and creating copies
Let me provide additional information.
The macro will be used by all sorts of people. I want to make it easy for them. There is a data folder and an archive folder. The macro process any file that sits in the data folder. After each file has been processed, a report is generated and written to the report folder that is dated and timeed stamped. I want to move all of the data files to the archive folder. I can do that now. But the person asking me to help create the macro is concerned that there might be the same files in the archive folder. I don't think that will happen but in case, I want to move the files and if the file already exist in the archive folder, I would like to rename it to some thing like "filename copy". Does that help? Thanks "Nils Titley" wrote: FSO.MoveFile With FSO.MoveFile, can you move the files and if they exist write them with a new name. If not how can I do that? Thanks |
#5
Posted to microsoft.public.excel.programming
|
|||
|
|||
Moving Files and creating copies
See also
http://www.rondebruin.nl/folder.htm -- Regards Ron de Bruin http://www.rondebruin.nl/tips.htm "Nils Titley" wrote in message ... Let me provide additional information. The macro will be used by all sorts of people. I want to make it easy for them. There is a data folder and an archive folder. The macro process any file that sits in the data folder. After each file has been processed, a report is generated and written to the report folder that is dated and timeed stamped. I want to move all of the data files to the archive folder. I can do that now. But the person asking me to help create the macro is concerned that there might be the same files in the archive folder. I don't think that will happen but in case, I want to move the files and if the file already exist in the archive folder, I would like to rename it to some thing like "filename copy". Does that help? Thanks "Nils Titley" wrote: FSO.MoveFile With FSO.MoveFile, can you move the files and if they exist write them with a new name. If not how can I do that? Thanks |
#6
Posted to microsoft.public.excel.programming
|
|||
|
|||
Moving Files and creating copies
Ron,
Thanks for the suggestion but I could not find in your pages what I need to do. "Ron de Bruin" wrote: See also http://www.rondebruin.nl/folder.htm -- Regards Ron de Bruin http://www.rondebruin.nl/tips.htm "Nils Titley" wrote in message ... Let me provide additional information. The macro will be used by all sorts of people. I want to make it easy for them. There is a data folder and an archive folder. The macro process any file that sits in the data folder. After each file has been processed, a report is generated and written to the report folder that is dated and timeed stamped. I want to move all of the data files to the archive folder. I can do that now. But the person asking me to help create the macro is concerned that there might be the same files in the archive folder. I don't think that will happen but in case, I want to move the files and if the file already exist in the archive folder, I would like to rename it to some thing like "filename copy". Does that help? Thanks "Nils Titley" wrote: FSO.MoveFile With FSO.MoveFile, can you move the files and if they exist write them with a new name. If not how can I do that? Thanks |
#7
Posted to microsoft.public.excel.programming
|
|||
|
|||
Moving Files and creating copies
You could try copying files individually using FSO File.Move, and if it
returns 'file exists' error (58), use a different name. Something like this (please be careful, this is not tested): strSourceFolder = "c:\source\" strDestFolder = "d:\destination\" Set objFso = CreateObject("Scripting.FileSystemObject") Set objSourceFolder = objFso.GetFolder(strSourceFolder) For Each objFile In objSourceFolder.Files On Error Resume Next objFile.Move strDestFolder If Err.Number = 58 Then i = 1 Do While Err.Number < 0 Err.Clear objFile.Move strDestFolder & "Copy Of " & _ objFso.GetBaseName(objFile) & _ " (" & i & ")" & "." & _ objFso.GetExtensionName(objFile.Path) i = i + 1 Loop Else Debug.Print Err.Number, Err.Description End If On Error GoTo 0 Next -- urkec "Nils Titley" wrote: Ron, Thanks for the suggestion but I could not find in your pages what I need to do. "Ron de Bruin" wrote: See also http://www.rondebruin.nl/folder.htm -- Regards Ron de Bruin http://www.rondebruin.nl/tips.htm "Nils Titley" wrote in message ... Let me provide additional information. The macro will be used by all sorts of people. I want to make it easy for them. There is a data folder and an archive folder. The macro process any file that sits in the data folder. After each file has been processed, a report is generated and written to the report folder that is dated and timeed stamped. I want to move all of the data files to the archive folder. I can do that now. But the person asking me to help create the macro is concerned that there might be the same files in the archive folder. I don't think that will happen but in case, I want to move the files and if the file already exist in the archive folder, I would like to rename it to some thing like "filename copy". Does that help? Thanks "Nils Titley" wrote: FSO.MoveFile With FSO.MoveFile, can you move the files and if they exist write them with a new name. If not how can I do that? Thanks |
#8
Posted to microsoft.public.excel.programming
|
|||
|
|||
Moving Files and creating copies
Hi Nils
Checking if each file exist in a loop is the only way. -- Regards Ron de Bruin http://www.rondebruin.nl/tips.htm "Nils Titley" wrote in message ... Ron, Thanks for the suggestion but I could not find in your pages what I need to do. "Ron de Bruin" wrote: See also http://www.rondebruin.nl/folder.htm -- Regards Ron de Bruin http://www.rondebruin.nl/tips.htm "Nils Titley" wrote in message ... Let me provide additional information. The macro will be used by all sorts of people. I want to make it easy for them. There is a data folder and an archive folder. The macro process any file that sits in the data folder. After each file has been processed, a report is generated and written to the report folder that is dated and timeed stamped. I want to move all of the data files to the archive folder. I can do that now. But the person asking me to help create the macro is concerned that there might be the same files in the archive folder. I don't think that will happen but in case, I want to move the files and if the file already exist in the archive folder, I would like to rename it to some thing like "filename copy". Does that help? Thanks "Nils Titley" wrote: FSO.MoveFile With FSO.MoveFile, can you move the files and if they exist write them with a new name. If not how can I do that? Thanks |
#9
Posted to microsoft.public.excel.programming
|
|||
|
|||
Moving Files and creating copies
Thanks for the help. I will give it a try. I dont' think it is necessary to
check if they exist but better to check than to get an error and have the move fail. I don't think it is necessary to check because I don't think there will be duplicate files. "Nils Titley" wrote: Ron, Thanks for the suggestion but I could not find in your pages what I need to do. "Ron de Bruin" wrote: See also http://www.rondebruin.nl/folder.htm -- Regards Ron de Bruin http://www.rondebruin.nl/tips.htm "Nils Titley" wrote in message ... Let me provide additional information. The macro will be used by all sorts of people. I want to make it easy for them. There is a data folder and an archive folder. The macro process any file that sits in the data folder. After each file has been processed, a report is generated and written to the report folder that is dated and timeed stamped. I want to move all of the data files to the archive folder. I can do that now. But the person asking me to help create the macro is concerned that there might be the same files in the archive folder. I don't think that will happen but in case, I want to move the files and if the file already exist in the archive folder, I would like to rename it to some thing like "filename copy". Does that help? Thanks "Nils Titley" wrote: FSO.MoveFile With FSO.MoveFile, can you move the files and if they exist write them with a new name. If not how can I do that? Thanks |
#10
Posted to microsoft.public.excel.programming
|
|||
|
|||
Moving Files and creating copies
Urkec,
Your code worked perfectly. Thanks for helping me. "urkec" wrote: You could try copying files individually using FSO File.Move, and if it returns 'file exists' error (58), use a different name. Something like this (please be careful, this is not tested): strSourceFolder = "c:\source\" strDestFolder = "d:\destination\" Set objFso = CreateObject("Scripting.FileSystemObject") Set objSourceFolder = objFso.GetFolder(strSourceFolder) For Each objFile In objSourceFolder.Files On Error Resume Next objFile.Move strDestFolder If Err.Number = 58 Then i = 1 Do While Err.Number < 0 Err.Clear objFile.Move strDestFolder & "Copy Of " & _ objFso.GetBaseName(objFile) & _ " (" & i & ")" & "." & _ objFso.GetExtensionName(objFile.Path) i = i + 1 Loop Else Debug.Print Err.Number, Err.Description End If On Error GoTo 0 Next -- urkec "Nils Titley" wrote: Ron, Thanks for the suggestion but I could not find in your pages what I need to do. "Ron de Bruin" wrote: See also http://www.rondebruin.nl/folder.htm -- Regards Ron de Bruin http://www.rondebruin.nl/tips.htm "Nils Titley" wrote in message ... Let me provide additional information. The macro will be used by all sorts of people. I want to make it easy for them. There is a data folder and an archive folder. The macro process any file that sits in the data folder. After each file has been processed, a report is generated and written to the report folder that is dated and timeed stamped. I want to move all of the data files to the archive folder. I can do that now. But the person asking me to help create the macro is concerned that there might be the same files in the archive folder. I don't think that will happen but in case, I want to move the files and if the file already exist in the archive folder, I would like to rename it to some thing like "filename copy". Does that help? Thanks "Nils Titley" wrote: FSO.MoveFile With FSO.MoveFile, can you move the files and if they exist write them with a new name. If not how can I do that? Thanks |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
How do I stop Excel 2007 from creating backup copies? | Excel Discussion (Misc queries) | |||
Moving between cells copies the screen! | Excel Discussion (Misc queries) | |||
how can i stop excel from automatically creating copies of workbo. | Excel Worksheet Functions | |||
How do I stop Excel from making copies of files? | Excel Discussion (Misc queries) | |||
Creating two linked copies of one workbook | Excel Discussion (Misc queries) |