+ Reply to Thread
Results 1 to 11 of 11

Copy files of a certain file name length, extension & modification date to another folder

  1. #1
    Forum Contributor
    Join Date
    01-30-2011
    Location
    Boston
    MS-Off Ver
    MS 365
    Posts
    225

    Copy files of a certain file name length, extension & modification date to another folder

    Copy only files of a certain file name length, extension & modification date to another folder

    Is it possible to have a simple macro that would copy files of a certain fixed length, extension and ideally modification date. The file names needing to be copied are made up of 10 digits only, always have .txt extension and modified 2018 or newer.

    Example file name: 1234567890.txt

    If I could make this using recorded macro that is something I can maybe handle, not handy with VBA. Not very advanced user.
    The .txt files reside in a folder named test and would like the files which meet the screening criteria copy to folder named qual.

    Thanks j

  2. #2
    Forum Expert CK76's Avatar
    Join Date
    06-16-2015
    Location
    ONT, Canada
    MS-Off Ver
    Office 365 ProPlus
    Posts
    5,883

    Re: Copy files of a certain file name length, extension & modification date to another fol

    Something like below.
    Syntax MoveFiles(Folder to search in, Destination Folder, file extension, start date)
    Note: Start date should match system's region setting format ("mm/dd/yyyy" etc).

    Please Login or Register  to view this content.
    Then use above in another sub, like...
    Please Login or Register  to view this content.
    Edit: I forgot about file name length. See below.
    Syntax: MoveFiles(Folder to search in, Destination Folder, length of file name before file extension, file extension, start date)
    Please Login or Register  to view this content.
    Last edited by CK76; 10-24-2018 at 01:26 PM.
    ?Progress isn't made by early risers. It's made by lazy men trying to find easier ways to do something.?
    ― Robert A. Heinlein

  3. #3
    Forum Contributor
    Join Date
    01-30-2011
    Location
    Boston
    MS-Off Ver
    MS 365
    Posts
    225

    Re: Copy files of a certain file name length, extension & modification date to another fol

    Thanks for the suggestion CK76, however I'm not sure if I can figure out that. I was trying to understand the code, does it screen for the 10 character fixed length? - That is one of the key needs. I did not point it out but the desired files are mixed in with other type file types and various file name lengths.

    -j

  4. #4
    Forum Expert CK76's Avatar
    Join Date
    06-16-2015
    Location
    ONT, Canada
    MS-Off Ver
    Office 365 ProPlus
    Posts
    5,883

    Re: Copy files of a certain file name length, extension & modification date to another fol

    See my edit.

  5. #5
    Forum Contributor
    Join Date
    01-30-2011
    Location
    Boston
    MS-Off Ver
    MS 365
    Posts
    225

    Re: Copy files of a certain file name length, extension & modification date to another fol

    Thanks. I'm pretty raw at this but enjoy trying to learn it and figure things out. It appears the initial folder where the multitude of files resides is folder named Test and the folder where the selected files go is a subfolder named Dest. I think there is a edit needed, the second to last line, need to change .xlsb to txt?

    Regards,

    j

  6. #6
    Forum Expert CK76's Avatar
    Join Date
    06-16-2015
    Location
    ONT, Canada
    MS-Off Ver
    Office 365 ProPlus
    Posts
    5,883

    Re: Copy files of a certain file name length, extension & modification date to another fol

    First Sub, MoveFiles is called in second Demo. Each of parameters in MoveFiles called in Demo, can be changed as you need.

    It will accept any file extension. ".xlsb", ".txt", ".csv" etc. You can adopt it to your need.

  7. #7
    Forum Contributor
    Join Date
    01-30-2011
    Location
    Boston
    MS-Off Ver
    MS 365
    Posts
    225

    Re: Copy files of a certain file name length, extension & modification date to another fol

    OK - I'll try to implement it. Thanks

  8. #8
    Forum Contributor
    Join Date
    01-30-2011
    Location
    Boston
    MS-Off Ver
    MS 365
    Posts
    225

    Re: Copy files of a certain file name length, extension & modification date to another fol

    Having trouble creating the macro correctly. Not sure what is needed to customize to my use. I did create the folder and sub folders and changed ".xlsb" to ".txt". I run the macro (I think) and there is no error nor are files moved as expected to the Dest folder. I'm very elementry when it comes to creating and customizing for my use.

    Regards,

    j

  9. #9
    Forum Expert CK76's Avatar
    Join Date
    06-16-2015
    Location
    ONT, Canada
    MS-Off Ver
    Office 365 ProPlus
    Posts
    5,883

    Re: Copy files of a certain file name length, extension & modification date to another fol

    Here's one way to implement it.

    I'd also recommend reading...
    https://www.rondebruin.nl/win/code.htm
    Attached Files Attached Files

  10. #10
    Forum Contributor
    Join Date
    01-30-2011
    Location
    Boston
    MS-Off Ver
    MS 365
    Posts
    225

    Re: Copy files of a certain file name length, extension & modification date to another fol

    Thanks for the demo file - got it to work! One issue is it does not leave the original file in place. I tried to figure it out by replacing the MoveFiles command with CopyFiles but no luck. Thanks for your efforts CK76.

    -j

  11. #11
    Forum Expert CK76's Avatar
    Join Date
    06-16-2015
    Location
    ONT, Canada
    MS-Off Ver
    Office 365 ProPlus
    Posts
    5,883

    Re: Copy files of a certain file name length, extension & modification date to another fol

    Then you need to change MoveFiles Sub to something like...
    Please Login or Register  to view this content.
    Notice that only change is made to "Name fold & myFile..." line.

+ 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. Replies: 18
    Last Post: 02-18-2019, 07:42 AM
  2. Copy multiple cells from all files in a folder into one file... its complicated.
    By jthorneuk in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 06-17-2015, 04:52 AM
  3. How to Rename the files extension in a Specific Folder
    By Kandavalli.Kiran in forum Excel Programming / VBA / Macros
    Replies: 21
    Last Post: 04-26-2015, 08:36 AM
  4. Copy Files from one folder to different folders based on pdf file name
    By jtammyg in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 01-23-2014, 11:49 AM
  5. Macro to copy some cells in some excel files in a folder to a master file
    By phemocheee in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 10-17-2013, 04:40 AM
  6. [SOLVED] Copy/paste Range of worksheets of several files in a folder to a master file
    By mrjinx007 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 06-18-2013, 01:02 PM
  7. Replies: 1
    Last Post: 01-15-2013, 03:05 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