+ Reply to Thread
Results 1 to 7 of 7

Macro to move file(s) based on wildcard description

  1. #1
    Registered User
    Join Date
    11-07-2007
    Posts
    9

    Macro to move file(s) based on wildcard description

    Good evening all,

    I've been working on a file tracking spreadsheet for the last few days and I am having a bit of difficulty with something I would like a macro to do.

    The basic idea of the current macro is to generate a checksum .sfv file containing filenames and CRC32s for various files and automatically give it a filename matching a template and containing today's date. For example:
    D:\SFV\A_File_With_Word_Docs-[2011-10-04].sfv
    D:\SFV\A_File_With_Excel_Docs-[2011-10-04].sfv

    This bit I have got working perfectly - however I would like to find a way of adding to this so that when a new file is being created by the macro, the 'existing' file (with a different date in the filename, most likely) is automatically either copied to another folder (as backup) and deleted, or is moved to this backup folder in one move.

    For example, on creation of A_File_With_Word_Docs-[2011-10-04].sfv, the existing file A_File_With_Word_Docs-[2011-10-03].sfv from yesterday is automatically detected (with a wildcard most likely) and the actions performed.

    I really hope that this is possible as it is a little beyond my knowledge of VBA at this stage! Thank you in advance for anybody who can help me; please let me know if you need any additional information that I may have forgotten to mention.
    Last edited by samf88; 10-05-2011 at 05:51 AM.

  2. #2
    Forum Contributor mccrimmon's Avatar
    Join Date
    02-19-2004
    Location
    Scotland
    MS-Off Ver
    2003
    Posts
    249

    Re: Macro to move file(s) based on wildcard description

    The below code should do the trick.

    Cheers

    Please Login or Register  to view this content.
    McCrimmon

  3. #3
    Registered User
    Join Date
    11-07-2007
    Posts
    9

    Re: Macro to move file(s) based on wildcard description

    Thanks for the quick reply mccrimmon - the code looks like it could potentially solve my exact problem; the only thing is I am having a bit of difficulty testing it before I implement it into my actual sheet.

    Whilst testing, the only changes I have made are:

    Please Login or Register  to view this content.
    Which returns me a run-time error 53 ("File not found") on this line:
    Please Login or Register  to view this content.
    Logic would indicate that this would be because there is no file with that filename and with a last modified date less than today; however this is not the case. I created the random file "sfv 0001.txt" and its' last modified date is 04 October 2011, today now being 05 October 2011. Do you have any ideas what the problem might be here? Once I get past this stage I can then re-implement the wild card and use the code over in my real workbook.

    Thanks for your help!
    Regards

  4. #4
    Forum Expert snb's Avatar
    Join Date
    05-09-2010
    Location
    VBA
    MS-Off Ver
    Redhat
    Posts
    5,649

    Re: Macro to move file(s) based on wildcard description

    Please Login or Register  to view this content.
    Last edited by snb; 10-05-2011 at 04:31 AM.



  5. #5
    Registered User
    Join Date
    11-07-2007
    Posts
    9

    Re: Macro to move file(s) based on wildcard description

    Thanks SNB,

    However I am getting the same runtime error as above; debugger states that it is in this part of the code. Any ideas what I may have done wrong?
    Please Login or Register  to view this content.
    I am testing this one with a file that I have created called "data_2011_01_01.xls" in "D:\test"

  6. #6
    Forum Expert snb's Avatar
    Join Date
    05-09-2010
    Location
    VBA
    MS-Off Ver
    Redhat
    Posts
    5,649

    Re: Macro to move file(s) based on wildcard description

    If the file hasn't been saved yet, that path part will be empty:
    amended code:

    Please Login or Register  to view this content.

  7. #7
    Registered User
    Join Date
    11-07-2007
    Posts
    9

    Re: Macro to move file(s) based on wildcard description

    FANTASTIC snb - I've managed to adapt that perfectly to work now. I think I love you! :D

    Thanks to both of you for your amazing help - I'll mark this as solved now.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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