Run a macro on multiple files in a folder

Posted on 2012-09-20
Last Modified: 2012-09-20
I have a working macro that does stuff to a file, saves and then closes it.  The macro is saved in my PERSONAL excel file, so it can be run on any excel file. Can somebody show me another macro or some other way to execute my existing macro on every file in a folder instead of having to manually execute it for each individual file?

Something like "For each file file in MyFolder, run MyMacro"
Question by:dbfromnewjersey
    LVL 19

    Accepted Solution

    in your VBA window ... in tools references... make sure you select "Microsoft Sripting Runtime"

    You can use the object browser in vba window (Hit F2) ... select Scripting library in the dropdown to see available methods with scripting library.

    Dim fso As New Scripting.FileSystemObject
    Dim FileObj As File
    Dim FolderObj as Folder
    FolderObj = fso.GetFolder("C:\someFolder")
    For Each FileObj in FolderObj.Files
      <Do something with file... by referencing FileObj>

    Open in new window


    Author Comment

    Thank you.

    Featured Post

    Looking for New Ways to Advertise?

    Engage with tech pros in our community with native advertising, as a Vendor Expert, and more.

    Join & Write a Comment

    What is a Form List Box? (skip if you know this) The forms List Box is the alternative to the ActiveX list box. If you are using excel 2007, you first make sure you have a developer tab (click the Orb)->"Excel Options"->Popular->"Show Developer tab…
    Introduction This Article is a follow-up to my Mappit! Addin Article (, it was inspired by an email posting I made to EUSPRIG (, I will briefly cover: 1) An overvie…
    This Micro Tutorial will demonstrate on a Mac how to change the sort order for chart legend values and decrpyt the intimidating chart menu.
    This Micro Tutorial will demonstrate the scrolling table in Microsoft Excel using the INDEX function.

    732 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    22 Experts available now in Live!

    Get 1:1 Help Now