+ Reply to Thread
Results 1 to 14 of 14

VB Code to Move Files

  1. #1
    Valued Forum Contributor
    Join Date
    01-18-2007
    Location
    Georgia
    MS-Off Ver
    2010
    Posts
    4,434

    VB Code to Move Files

    Hello:

    Please refer to attached file.
    I have lot of Stores and i have created Folder for each Stores to store scanned files
    Main folder for each store is in C:\Dropbox\
    and each store have sub folders listed in cell C6 down

    For example :
    Store1

    C:\Dropbox\Store1
    C:\Dropbox\Store1\BankStatement
    C:\Dropbox\Store1\CDI
    C:\Dropbox\Store1\DQStore_Rep

    and so on...

    Now I scanned all invoices etc for all stores once a week.
    All Scanned files for all stores will be at location in cell E4:
    C:\Dropbox\1Scanned\

    Each scanned file will have names as follows:

    mm-dd-yyyy-StoreName-Catagory.pdf

    I need a VB Code to move the files to correct StoreName and correct category folder.

    For Example:

    10-22-2015-Store1-BankStatement needs to be moved from C:\Dropbox\1Scanned to C:\Dropbox\Store1\BankStatement
    10-22-2015-Store3-CDI needs to be moved from C:\Dropbox\1Scanned to C:\Dropbox\Store2\CDI

    Let me know if you have any questions.
    Thanks.
    RM
    Attached Files Attached Files
    Last edited by rizmomin; 10-22-2015 at 05:24 PM.

  2. #2
    Forum Expert
    Join Date
    08-02-2013
    Location
    Québec
    MS-Off Ver
    Excel 2003, 2007, 2013
    Posts
    1,414

    Re: VB Code to Move Files

    Hello rizmomin,

    Here's a suggestion :
    Please Login or Register  to view this content.
    GC Excel

    If this post helps, then click the star icon (*) in the bottom left-hand corner of my post to Add reputation.

  3. #3
    Valued Forum Contributor
    Join Date
    01-18-2007
    Location
    Georgia
    MS-Off Ver
    2010
    Posts
    4,434

    Re: VB Code to Move Files

    Hi GC:

    While running the, it gives error at
    Please Login or Register  to view this content.
    Not sure why....would appreciate your help to check.
    Also would like to add 2 features:
    1. If the StoreName folder and Subfolder (Catagory) at destination does not exist then create one.
    2. If the file name at the source does not meet the name specification then ignore that file and do not move.

    NOTE : Just to let you know that the file name is in the following format:

    10-22-2015-Store1_BankStatement instead of 10-22-2015-Store1-BankStatement as earlier mentioned.

    Sorry for this..

    Please let me know if you have any questions.
    Thanks.

    RM
    Last edited by rizmomin; 10-23-2015 at 10:37 AM.

  4. #4
    Valued Forum Contributor
    Join Date
    01-18-2007
    Location
    Georgia
    MS-Off Ver
    2010
    Posts
    4,434

    Re: VB Code to Move Files

    Hi GC:

    I think i found where the error was in the code and corrected..
    Please Login or Register  to view this content.
    I have corrected and seems to work great.
    Would appreciate if you can help adding the 2 features i have mentioned.

    Thanks a lot for great help.
    Riz

  5. #5
    Forum Expert
    Join Date
    08-02-2013
    Location
    Québec
    MS-Off Ver
    Excel 2003, 2007, 2013
    Posts
    1,414

    Re: VB Code to Move Files

    Hi Riz,

    You're correct about the error (copy paste error from my side).
    I'll get back to you later tonight to create the folder and subfolder it they do not already exist. The files should already be ignored but I'll double check at the same time.

  6. #6
    Forum Expert
    Join Date
    08-02-2013
    Location
    Québec
    MS-Off Ver
    Excel 2003, 2007, 2013
    Posts
    1,414

    Re: VB Code to Move Files

    Hi Riz,

    Here's an a new version of the code. The folders and subfolders will all be created automatically.
    Fill will ignored if it doesn't meet the specification.

    Let me know if you have any questions.


    Please Login or Register  to view this content.

  7. #7
    Valued Forum Contributor
    Join Date
    01-18-2007
    Location
    Georgia
    MS-Off Ver
    2010
    Posts
    4,434

    Re: VB Code to Move Files

    Hi GC:

    Seems to work but it is creating all sub-folders (Catagory) for a STORE even if the files for that particcular catagory does not exist.
    Example:

    Currently i only have 1 Sub Folder (Catagory1) for STORE1
    Now assume that the file which we will move has STORE1 with Catagory2.
    In this case we need to create ONLY catogory2 in Store1 foldder.

    The code currently creates all Catagory folders in STORE1.

    Please let me know if you have any questions.
    Thanks.

    Riz
    Last edited by rizmomin; 10-24-2015 at 09:49 PM.

  8. #8
    Forum Expert
    Join Date
    08-02-2013
    Location
    Québec
    MS-Off Ver
    Excel 2003, 2007, 2013
    Posts
    1,414

    Re: VB Code to Move Files

    Hi Riz,

    Sorry for the late reply, I was out of town yesterday... Here's an amended version of the code. Only the required folders will be created.

    Please Login or Register  to view this content.

  9. #9
    Valued Forum Contributor
    Join Date
    01-18-2007
    Location
    Georgia
    MS-Off Ver
    2010
    Posts
    4,434

    Re: VB Code to Move Files

    Hi GC:

    Works great now....Thanks a lot

    RM

  10. #10
    Valued Forum Contributor
    Join Date
    01-18-2007
    Location
    Georgia
    MS-Off Ver
    2010
    Posts
    4,434

    Re: VB Code to Move Files

    Hi GC:

    Would like to add one more feature in this code or may be separate code.
    As you know we have STORENAME folder and Subfolders.
    I need a CODE to go thru each STORENAME/SUBFolders and copy the files and paste in C:\Dropbox\1Scanned (location is at cell E4).
    Please let me know if you have any questions.
    Thanks.

    Riz

  11. #11
    Forum Expert
    Join Date
    08-02-2013
    Location
    Québec
    MS-Off Ver
    Excel 2003, 2007, 2013
    Posts
    1,414

    Re: VB Code to Move Files

    Hi Riz,

    Again sorry for the late response... I was quite busy today :
    Here's a new code to try to move all files to the destination (scanned) folder.
    Note that the STORENAME/SUBFOLDERS are not deleted (is it required ?)

    Please Login or Register  to view this content.

  12. #12
    Valued Forum Contributor
    Join Date
    01-18-2007
    Location
    Georgia
    MS-Off Ver
    2010
    Posts
    4,434

    Re: VB Code to Move Files

    Hi GC :

    Small corrections.
    I wanted to copy the files and not move as I had mentioned.
    Would appreciate if you could modify the code.
    Thanks a lot
    RM

  13. #13
    Forum Expert
    Join Date
    08-02-2013
    Location
    Québec
    MS-Off Ver
    Excel 2003, 2007, 2013
    Posts
    1,414

    Re: VB Code to Move Files

    Simply remove this line of code :
    Please Login or Register  to view this content.

  14. #14
    Valued Forum Contributor
    Join Date
    01-18-2007
    Location
    Georgia
    MS-Off Ver
    2010
    Posts
    4,434

    Re: VB Code to Move Files

    Hi GC:

    Superb....Thanks a lot

    RM

+ 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: 1
    Last Post: 05-29-2015, 10:40 AM
  2. VBA code to move multiple files to different folders based on the file name
    By MissaLissa in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 04-07-2015, 10:19 AM
  3. Macro to move code to cell, print, then move down the list to the next code
    By MilesDeep in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 05-09-2014, 04:59 PM
  4. Replies: 2
    Last Post: 02-10-2014, 11:52 AM
  5. [SOLVED] VBA Code to Move Excel files from one folder to another
    By MHamid in forum Excel Programming / VBA / Macros
    Replies: 12
    Last Post: 09-04-2013, 12:33 PM
  6. Excel Macro Code Request for List files and Move specified directory
    By ganeshinscribe in forum Excel Programming / VBA / Macros
    Replies: 14
    Last Post: 03-19-2012, 08:38 AM
  7. Problem with code - move files to another directory
    By uncleslinky in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 03-14-2011, 10:06 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