+ Reply to Thread
Results 1 to 8 of 8

Loop through all Excel files in subfolders and run macros in each

  1. #1
    Forum Contributor
    Join Date
    12-24-2016
    Location
    London
    MS-Off Ver
    2013
    Posts
    153

    Loop through all Excel files in subfolders and run macros in each

    Dear Excel Gurus,

    I'm very new to the world of VBA, but I need a VBA script which can scan main folder and all sub-folders for "*.xl*" files and run in each sequentially 2 macros: 1) modify header/footer and 2) insert picture. I found two codes and edited them to fit my needs. Ideally, I would like to combine both macros into one and then loop all Excel files with it.

    For headers/footers:

    Please Login or Register  to view this content.
    Insert logo:
    Please Login or Register  to view this content.
    Last major notice: each workbook should be saved and closed after the macro completes

    I will be appreciate for any help Thanks in advance!

  2. #2
    Forum Expert WideBoyDixon's Avatar
    Join Date
    10-03-2016
    Location
    Sheffield, UK
    MS-Off Ver
    365
    Posts
    2,182

    Re: Loop through all Excel files in subfolders and run macros in each

    Completely untested but this might work:

    Please Login or Register  to view this content.
    WBD
    Office 365 on Windows 11, looking for rep!

  3. #3
    Forum Contributor
    Join Date
    12-24-2016
    Location
    London
    MS-Off Ver
    2013
    Posts
    153

    Re: Loop through all Excel files in subfolders and run macros in each

    I had received compile Error on this line
    Please Login or Register  to view this content.
    What is a mistake? Do I need to run macro "ScanFolderForXls"?

  4. #4
    Forum Contributor
    Join Date
    12-24-2016
    Location
    London
    MS-Off Ver
    2013
    Posts
    153

    Re: Loop through all Excel files in subfolders and run macros in each

    Dear WBD,

    I delete some Reference in VBA project and there is no mistake in this line. But nothing happens with footers/headers in the files...

    Where can be error and what I am doing wrong?

  5. #5
    Forum Expert WideBoyDixon's Avatar
    Join Date
    10-03-2016
    Location
    Sheffield, UK
    MS-Off Ver
    365
    Posts
    2,182

    Re: Loop through all Excel files in subfolders and run macros in each

    Hey,

    I have no idea. I just ran a test with the code and all the headers/footers in my files were changed correctly.

    WBD

  6. #6
    Forum Expert
    Join Date
    04-23-2009
    Location
    Matrouh, Egypt
    MS-Off Ver
    Excel 2013
    Posts
    6,882

    Re: Loop through all Excel files in subfolders and run macros in each

    Hello
    Can you post sample of your files to test?
    < ----- Please click the little star * next to add reputation if my post helps you
    Visit Forum : From Here

  7. #7
    Forum Contributor
    Join Date
    12-24-2016
    Location
    London
    MS-Off Ver
    2013
    Posts
    153

    Re: Loop through all Excel files in subfolders and run macros in each

    Hey Hey,

    Sorry it is my fault...I forgot to delete old macros. Everything works, shake your hand again

    BR,
    Igor

  8. #8
    Forum Expert WideBoyDixon's Avatar
    Join Date
    10-03-2016
    Location
    Sheffield, UK
    MS-Off Ver
    365
    Posts
    2,182

    Re: Loop through all Excel files in subfolders and run macros in each

    Excellent. Please mark the thread as solved.

    WBD

+ 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] list of subfolders in folder - without files and sub-subfolders
    By MartyZ in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 06-11-2022, 10:56 AM
  2. Get Value Function Loop through all files in folder and its subfolders
    By Cheeseburger in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 03-27-2016, 06:19 PM
  3. Loop through multiple files and call macros (but unable to loop)
    By ryanpetersen in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 05-23-2014, 12:04 PM
  4. [SOLVED] Reading Excel files in folder/subfolders
    By crakter in forum Excel Programming / VBA / Macros
    Replies: 19
    Last Post: 02-21-2014, 05:48 AM
  5. [SOLVED] Files within Multiple SubFolders and SubFolders Within It
    By codeslizer in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 09-18-2013, 04:18 AM
  6. [SOLVED] Amending various excel files including those in subfolders MACRO
    By gonzalraf in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 01-20-2013, 02:15 PM
  7. [SOLVED] copy subfolders, replace text in files and save files in copied subfolders
    By pieros in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 11-01-2005, 09: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