+ Reply to Thread
Results 1 to 3 of 3

Re: Move Files from folder and sub folder based on date

  1. #1
    Spammer
    Join Date
    08-20-2012
    Location
    Canada
    MS-Off Ver
    2007
    Posts
    221

    Re: Move Files from folder and sub folder based on date

    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
    Attached Files Attached Files
    Last edited by flupsie; 10-08-2017 at 09:20 AM.

  2. #2
    Forum Expert Kenneth Hobson's Avatar
    Join Date
    02-05-2007
    Location
    Tecumseh, OK
    MS-Off Ver
    Office 365, Win10Home
    Posts
    2,573

    Re: Move Files from folder and sub folder based on date

    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.

  3. #3
    Spammer
    Join Date
    08-20-2012
    Location
    Canada
    MS-Off Ver
    2007
    Posts
    221

    Re: Move Files from folder and sub folder based on date

    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

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. [SOLVED] Move row to new tab based on a date being entered
    By hazelwouldbe in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 05-30-2016, 08:58 AM
  2. Move data based on date
    By tommywat in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 06-12-2015, 08:26 AM
  3. Move data fro one sheet to another based on date
    By Clemme in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 11-24-2013, 08:22 AM
  4. Move Row in excel based on a date
    By jmmcneil in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 10-18-2012, 03:03 AM
  5. [SOLVED] Move a Rowto a section based on the date
    By -EA- in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 10-04-2012, 12:15 AM
  6. Move and paste entire row based on date
    By Gal72 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 09-12-2012, 06:42 PM
  7. Move Files Based On date in Name
    By erock24 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 12-02-2009, 06:32 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1