+ Reply to Thread
Results 1 to 8 of 8

edit macro to make it run on all files in a folder

  1. #1
    Registered User
    Join Date
    11-19-2012
    Location
    india
    MS-Off Ver
    Excel 2007
    Posts
    81

    edit macro to make it run on all files in a folder

    Hi! All,

    Please find a macro below. All I want is to edit this macro so that it runs on all the files in a particular folder

    Please Login or Register  to view this content.
    Last edited by JBeaucaire; 06-09-2013 at 05:55 PM. Reason: Added CODE tags, as per Forum Rules. Take a moment to read the Forum Rules in the menu bar above. Thanks.

  2. #2
    Registered User
    Join Date
    11-19-2012
    Location
    india
    MS-Off Ver
    Excel 2007
    Posts
    81

    Re: edit macro to make it run on all files in a folder

    can anyone edit the above mentioned macro so that it runs on all the files in a particular folder

  3. #3
    Forum Guru HaHoBe's Avatar
    Join Date
    02-19-2005
    Location
    Hamburg, Germany
    MS-Off Ver
    work: 2016 on Win10 (notebook), private: 2019 on Win10 (desktop), 2019 on Win11 (notebook)
    Posts
    8,198

    Re: edit macro to make it run on all files in a folder

    Hi, rohit43,

    you could have edited the originla post instead of reposting.

    Maybe like this (untested)
    Please Login or Register  to view this content.
    But I strongly doubt that you have a lot of workbooks with a sheet named Jun8 in that folder.

    Ciao,
    Holger
    Use Code-Tags for showing your code: [code] Your Code here [/code]
    Please mark your question Solved if there has been offered a solution that works fine for you

  4. #4
    Registered User
    Join Date
    11-19-2012
    Location
    india
    MS-Off Ver
    Excel 2007
    Posts
    81

    Re: edit macro to make it run on all files in a folder

    Hi! Holger,
    I am sorry to say but this didn't work. I am not very good with macros. The one posted was actually recorded by me. Can you edit the same macro so that it automatically runs on all the workbooks in a particular folder.
    All the workbooks in the folder are exactly the same with different workbook names. And the the workbook contains same sheets with same sheet names. The comments on each workbook are different as they are filled by different users.

  5. #5
    Forum Guru HaHoBe's Avatar
    Join Date
    02-19-2005
    Location
    Hamburg, Germany
    MS-Off Ver
    work: 2016 on Win10 (notebook), private: 2019 on Win10 (desktop), 2019 on Win11 (notebook)
    Posts
    8,198

    Re: edit macro to make it run on all files in a folder

    Hi, rohit43,

    I am sorry to say but this didn't work.
    Could you be a bit more specific about what didnīt work? Any error messages put up, error numbers shown, files not opening, no new sheets entered?

    Can you edit the same macro so that it automatically runs on all the workbooks in a particular folder.
    Have you tried your macro on more than one file with success?

    I wouldnīt rewrite all the code (since my efforts didnīt work) but use a wrapper for opening and closing the files and use the existing macro to do the work (which could need a good boost of work):
    Please Login or Register  to view this content.
    Ciao,
    Holger

  6. #6
    Registered User
    Join Date
    11-19-2012
    Location
    india
    MS-Off Ver
    Excel 2007
    Posts
    81

    Re: edit macro to make it run on all files in a folder

    Hi! Holger,

    Could you be a bit more specific about what didnīt work?
    No new sheets were entered

    Have you tried your macro on more than one file with success?
    Yes it works on all other worksheets in that folder if I run it seperately on each one of them.

    As I said earlier, I am not good with macros. I can only record macros and run a given macro. I am not able to understand the macro that you have given me. I don't know if I need to add this to my macro or run it as a seperate one.

    Is it possible for you to give me some commands which can be added in the beginning or end of my recorded macro so that it runs on the rest of the files as well. I am also okay to keep the other files opened at the same time if that helps.

    thanks so much for all your efforts and pain.

  7. #7
    Forum Guru HaHoBe's Avatar
    Join Date
    02-19-2005
    Location
    Hamburg, Germany
    MS-Off Ver
    work: 2016 on Win10 (notebook), private: 2019 on Win10 (desktop), 2019 on Win11 (notebook)
    Posts
    8,198

    Re: edit macro to make it run on all files in a folder

    Hi, rohit43,

    I checked my code on one sample workbook, sheets were inserted there as expected, no error messages - after I corrected a mistake which caused a run-time error (funny it didnīt show up on your system).

    Please Login or Register  to view this content.
    must read
    Please Login or Register  to view this content.
    Please find the workbook I used for this as an attachment.

    Execution is quite simple: look at the directory which is given, create a collection of all workbooks that meet the criteria in that directory, loop through all of them and insert the given number of worksheets as a copy of the one which is stated as master, clear the contents, rename them according to the array, close the workbook with saving the changes, loop until no workbook is left over.

    Ciao,
    Holger
    Attached Files Attached Files

  8. #8
    Valued Forum Contributor rollis13's Avatar
    Join Date
    01-26-2012
    Location
    Cordenons
    MS-Off Ver
    Excel 2016 32bit - Win 11
    Posts
    917

    Re: edit macro to make it run on all files in a folder


+ 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