+ Reply to Thread
Results 1 to 13 of 13

VBA Code to Move Excel files from one folder to another

  1. #1
    Registered User
    Join Date
    12-03-2012
    Location
    New Castle, DE
    MS-Off Ver
    Excel 2007
    Posts
    65

    VBA Code to Move Excel files from one folder to another

    Hello All,

    I need some help/advise.

    Is there a way to copy files from one folder to another using a VBA code?
    I have a list of accounts where I will need to copy files from on folder to another. The thing is that there are over 50 accounts and I honestly don't feel like copying them one by one.

    For instance, I have to copy a file for acct#1234567890. The excel files that I would have to copy are as follows:
    1234567890_Top Sheet_2013.xls
    1234567890_Rec Worksheet_2013.xls

    The folder where the excel files are for that particular account would be:
    K:\shared\InvestorBankRec\Reconciliations\1234567890
    The folder where the excel files would have to be moved to would be:
    K:\shared\InvestorBankRec\Audits\W2 07-2013

    Then there is also a pdf file that will have to be moved from:
    K:\shared\InvestorBankRec\Electronic Bank Statements\2013\07-2013\DDAUSA-111-1234567890-2013-07-31-39914276.pdf
    The account number will always be after the 111- and before the -2013.
    The folder where the pdf file would have to be moved to would be:
    K:\shared\InvestorBankRec\Audits\W2 07-2013



    Technically there are over 500 accounts where this would have to be done to and I was looking for a VBA code that would do that for us.

    Would this be possible? I have no idea how to start the code, therefore I don't have a code written for this yet.
    Please help if you can.

    Thank you,
    Miriam

  2. #2
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: VBA Code to Move Excel files from one folder to another

    Are these account numbers listed on a sheet to manage this process from?

    What is sheet name?
    What column has these account numbers?
    Is there any other data in that same column anywhere to cause an issue?
    Do we want to "mark" the account numbers that were successfully found and moved, or mark the ones that weren't found, in some way?
    _________________
    Microsoft MVP 2010 - Excel
    Visit: Jerry Beaucaire's Excel Files & Macros

    If you've been given good help, use the icon below to give reputation feedback, it is appreciated.
    Always put your code between code tags. [CODE] your code here [/CODE]

    ?None of us is as good as all of us? - Ray Kroc
    ?Actually, I *am* a rocket scientist.? - JB (little ones count!)

  3. #3
    Registered User
    Join Date
    12-03-2012
    Location
    New Castle, DE
    MS-Off Ver
    Excel 2007
    Posts
    65

    Re: VBA Code to Move Excel files from one folder to another

    Yes, the accounts are currenly listed in the following spreadsheet located at:
    C:\Documents and Settings\mhamid\Desktop\Wave 2 Accts\Waive2PIAccounts.xls

    There is only one tab in that sheet and the account numbers are listed in column A. There is no other data in column A that would cause any issue.
    The only other data in the sheet is in column B where we have the people's name who are responsible for each aprticualr account. That can be ignored completely as it will not be relevant to the VBA code.

    Yes, we can mark the account numbers that were succesfully found and moved or vice-versa in column C, if possible.


    Thank you,
    Miriam

  4. #4
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: VBA Code to Move Excel files from one folder to another

    Would the macro be run FROM inside the Waive2PIAccounts.xls workbook, or from a separate workbook? In that workbook, the first account number is listed in A1? Or A2? ??

  5. #5
    Registered User
    Join Date
    12-03-2012
    Location
    New Castle, DE
    MS-Off Ver
    Excel 2007
    Posts
    65

    Re: VBA Code to Move Excel files from one folder to another

    I would prefer the macro to be run from a separete workbook where people can just copy their accounts and run the macro.

    The accounts are currenly listed from cell A2 in the Waive2PIAccounts.xls workbook.


    Thank you

  6. #6
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: VBA Code to Move Excel files from one folder to another

    In this example folder:

    K:\shared\InvestorBankRec\Reconciliations\1234567890\

    you note these two files to be moved:
    1234567890_Top Sheet_2013.xls
    1234567890_Rec Worksheet_2013.xls


    Are there other files in that folder to be ignored, or are these two always the only files in there? I ask because if this represents all the contents, we could just move the folder as a whole rather than file by file.

  7. #7
    Registered User
    Join Date
    12-03-2012
    Location
    New Castle, DE
    MS-Off Ver
    Excel 2007
    Posts
    65

    Re: VBA Code to Move Excel files from one folder to another

    There are other files and subfolder within the account # folder. Everything else is to be ignored except for the two files I mentioned.
    I only need the files specified files moved.


    Thank you

  8. #8
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: VBA Code to Move Excel files from one folder to another

    This seems like it should work, then. It will note off to the right any files it cannot find.

    Please Login or Register  to view this content.

  9. #9
    Registered User
    Join Date
    12-03-2012
    Location
    New Castle, DE
    MS-Off Ver
    Excel 2007
    Posts
    65

    Re: VBA Code to Move Excel files from one folder to another

    The code works great, but I actually needed it to make a copy of both the excel and pdf files to the Audits folder. Is there a way to correct the code?

    Thank you

  10. #10
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: VBA Code to Move Excel files from one folder to another

    Copying files, not moving them? Hm, will have to look at it later. Time for work.

  11. #11
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: VBA Code to Move Excel files from one folder to another

    Try this instead:
    Please Login or Register  to view this content.

  12. #12
    Registered User
    Join Date
    12-03-2012
    Location
    New Castle, DE
    MS-Off Ver
    Excel 2007
    Posts
    65

    Re: VBA Code to Move Excel files from one folder to another

    This worked perfectly.

    Is it possible you can explain how the code worked? For intance, what part of the code made it possible not to duplicate anything that was previously copied?

    Thank you,
    ~Miriam

  13. #13
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: VBA Code to Move Excel files from one folder to another

    Nothing prevents duplication. If the list of account numbers includes duplicated account numbers, the files will be copied twice. But that's harmless, you can only have one file named one thing in one folder, so the new copies simply overwrite the existing.

+ 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] Excel VBA code for selecting a folder then search & open specified files in that folder
    By Excelrookie_1 in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 08-27-2021, 03:09 AM
  2. Replies: 1
    Last Post: 01-28-2019, 06:55 PM
  3. Move Excel files from One folder to another
    By yus786 in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 04-04-2013, 05:58 AM
  4. Move Excel files to an Outlook folder
    By ninja0059 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 02-22-2008, 02:18 AM
  5. Move Files from Folder to Folder
    By THE_RAMONES in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 05-25-2006, 04:25 PM

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