+ Reply to Thread
Results 1 to 5 of 5

Cycling through folders and changing excel files within each folder

  1. #1
    Registered User
    Join Date
    07-18-2014
    Location
    Florida, US
    MS-Off Ver
    7
    Posts
    2

    Question Cycling through folders and changing excel files within each folder

    Hi,

    I am using individual excel files in separate folders to store inspection plans for thousands of parts. I have created close to 3,000 excel files, and now I am told I need to change the header and footer, or else we may get dinged in an audit. I need a way to cycle through each folder (which we will call MOLD#) in a main folder (which we will call Q), and open every excel file in the folder called INSPECTION PLAN, and change the footer/header.

    Q
    ~~MOLD#1
    ~~~~INSPECTION PLAN
    ~~~~~~Excel file1 <------ need to change this
    ~~MOLD#2
    ~~~~INSPECTION PLAN
    ~~~~~~Excel file1 <------ need to change this
    ~~~~~~Excel file2 <------ need to change this
    etc....

    Also to complicate things, the folder INSPECTION PLAN may or may not exist. If it doesn't exist, then it should just skip to the next MOLD#.

    I can take care of the rest of the programming, I just cannot seem to find a program to do the folder cycling I am looking for. Any help will be much appreciated.

  2. #2
    Forum Expert
    Join Date
    11-22-2016
    Location
    Cornwall,UK
    MS-Off Ver
    office 365
    Posts
    4,240

    Re: Cycling through folders and changing excel files within each folder

    - look in main folder Q
    - loop every sub-folder whose name ALWAYS begins with the 4 characters "Mold"
    - look for file named Inspection Plan (does each file have extension xlsx ?) (ie name is always Inspection Plan.xlsx)
    - is Excel File 1/ File 2 in the footer, the header, either, or both?
    - what replaces File 1 & File 2?
    Click *Add Reputation to thank those who helped you. Ask if anything is not clear

  3. #3
    Forum Expert
    Join Date
    11-22-2016
    Location
    Cornwall,UK
    MS-Off Ver
    office 365
    Posts
    4,240

    Re: Cycling through folders and changing excel files within each folder

    I can take care of the rest of the programming, I just cannot seem to find a program to do the folder cycling I am looking for
    This code does the cycling
    Amend to match your requirements

    I set up this structure
    C:\TestArea\Mold1\Inspection Plan.xlsx
    C:\TestArea\Mold2\Inspection Plan.xlsx
    C:\TestArea\Mold3\Inspection Plan.xlsx

    Each file named Inspection Plan.xlsx opened in sequence with the code below:

    Please Login or Register  to view this content.
    Please Login or Register  to view this content.
    Last edited by kev_; 01-03-2018 at 09:39 AM.

  4. #4
    Registered User
    Join Date
    07-18-2014
    Location
    Florida, US
    MS-Off Ver
    7
    Posts
    2

    Re: Cycling through folders and changing excel files within each folder

    Thank you so much kev!

    I took the code you provided and I am now able to cycle through my folders. I had to amend it to go one folder deeper, as the files I need to amend would be 2 subfolders down from the host folder. Also the mold# and inspection plan.xlsx file names vary, so I took out the if statements.

    Please Login or Register  to view this content.

  5. #5
    Forum Expert
    Join Date
    11-22-2016
    Location
    Cornwall,UK
    MS-Off Ver
    office 365
    Posts
    4,240

    Re: Cycling through folders and changing excel files within each folder

    Glad you got your solution
    Thanks for the rep and for marking thread as solved

+ 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] VBA to loop through a folder and all sub folders opening excel files.
    By Lsxtrkiller in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 06-07-2017, 06:18 PM
  2. Needs macro to copy excel files from folders, subfolders to new folder
    By genetist in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 10-08-2014, 08:53 AM
  3. [SOLVED] VBA not cycling through and processing all files in folder
    By DaveBre in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 05-07-2014, 05:56 AM
  4. Open ALL excel files on a folder, on different folders
    By ferrariako in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 05-13-2013, 09:54 PM
  5. Replies: 1
    Last Post: 02-29-2012, 01:15 PM
  6. cycling through all sub-folders in a folder
    By dyesol in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 06-15-2011, 10:31 AM
  7. Cycling through files in a folder
    By KateMolloy in forum Excel Programming / VBA / Macros
    Replies: 10
    Last Post: 09-28-2009, 04:18 PM

Tags for this Thread

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