+ Reply to Thread
Results 1 to 6 of 6

Loop Through all files in a folder and use the same macro to edit each one.

  1. #1
    Registered User
    Join Date
    09-17-2012
    Location
    USA
    MS-Off Ver
    Excel 2010
    Posts
    5

    Loop Through all files in a folder and use the same macro to edit each one.

    I am using the PERSONAL.XLSB to store my macro that I want to use on each file in a specific folder.
    It works all the way through the first file, then I get I get a runtime error 91, object variable not set. It stops at this line:
    Please Login or Register  to view this content.
    Any help will be appreciated.
    Here is the entire code:

    Please Login or Register  to view this content.

  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: Loop Through all files in a folder and use the same macro to edit each one.

    It doesn't appear the files are being explicitly opened. Something like this:

    Please Login or Register  to view this content.
    Last edited by JBeaucaire; 09-18-2012 at 12:47 PM.
    _________________
    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
    09-17-2012
    Location
    USA
    MS-Off Ver
    Excel 2010
    Posts
    5

    Re: Loop Through all files in a folder and use the same macro to edit each one.

    I am trying the code you posted, however now I get the error message; "runtime error 1004 method add of object sheets failed".
    In my original code I was beginning with "Option Explicit", I apologize for not having that in my posted code.
    Thanks for looking at this.

  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: Loop Through all files in a folder and use the same macro to edit each one.

    My apologies, the code above is corrected.

  5. #5
    Registered User
    Join Date
    09-17-2012
    Location
    USA
    MS-Off Ver
    Excel 2010
    Posts
    5

    Re: Loop Through all files in a folder and use the same macro to edit each one.

    Excellent! 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: Loop Through all files in a folder and use the same macro to edit each one.

    I have marked this thread solved for you.

    In the future please select Thread Tools from the menu above and mark the thread as solved. Thanks.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

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