I have code to move files in a folder and sub-folder. Hover of file already exists in the folder to be moved to I get a error
If file already exists, then file to be overwritten
Kindly amend my code
I have code to move files in a folder and sub-folder. Hover of file already exists in the folder to be moved to I get a error
If file already exists, then file to be overwritten
Kindly amend my code
Last edited by flupsie; 10-08-2017 at 09:20 AM.
Your code exits the Sub if the MsgBox response overwrite is not vbYes. I don't think that was your intent.
If you wanted overwrite to happen or not for each file in target folder/subfolder(s), you should check if the file exists. Dir() can be used but since you are using fso anyway, you can use fso.FileExists() to check that. Your If() will also need to consider that and the value of overwrite before the fso.Move.
Even with all of these changes, which I could show you how to do, I fear that things may still go amiss. e.g. Source folder has no files in it but one or more of the Subfolders do. Normally, I create an array with all of the source folder filenames including those in subfolders. I can then act on each file accordingly.
I can show you my standard batch method if you like.
Or, you might want to explore RoboCopy. This goes back to the old days of DOS. If you type cmd in the Run window, Win+R, and press enter key you will be at a command prompt. Type: Help RoboCopy to see what switches it allows. Type exit and press enter key to exit that window. Or, view the same help at: https://ss64.com/nt/robocopy.html
Few people use commands like xcopy and robocopy. They still provide a lot of power. Before doing it, try manual runs at the command prompt. If you go that route, post what you used. I can show you how to automate it from VBA.
If you just want to tweak your routine and have trouble doing what I explained, please post back. So, solutions would be: (1) A batch file list method, (2) robocopy, and (3) tweak your routine.
As in all tasks like these, be sure to backup your data first.
Thanks for the help, Kenneth
Kindly tweak my routine. I will then go through the code to see where I went wrong and thus learn from where I went wrong
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks