+ Reply to Thread
Results 1 to 9 of 9

Save all worksheets in a folder (incl subfolders) as separate files (w/o name conflicts)

  1. #1
    Registered User
    Join Date
    09-06-2011
    Location
    Paris
    MS-Off Ver
    Excel 2003
    Posts
    23

    Save all worksheets in a folder (incl subfolders) as separate files (w/o name conflicts)

    I would like to extend the capability of this code taken from http://superuser.com/questions/56192...heets-into-sep, which allows worksheets in a workbook to be saved as a separate files.

    Please could you suggest how:

    1) it can be adapted to loop through all closed Excel files in a folder (including subfolders) so that it's not just run on the Active Workbook
    2) the files which are created are named so that conflicts are avoided (so that lots of "Sheet1's" don't cause problems). Ideally, the name of the file would be the original workbook name plus the worksheet name.

    Many thanks

    Please Login or Register  to view this content.

  2. #2
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,258

    Re: Save all worksheets in a folder (incl subfolders) as separate files (w/o name conflict

    Hello 1819,

    Add a new VBA module to your workbook's VBA Project. Copy and paste the code below into it.

    The macro is set to search for "xlsx" files but can be changed to search for more than one file type. If you need to do this, let me know so I can adjust it for you.

    Please Login or Register  to view this content.
    Sincerely,
    Leith Ross

    Remember To Do the Following....

    1. Use code tags. Place [CODE] before the first line of code and [/CODE] after the last line of code.
    2. Thank those who have helped you by clicking the Star below the post.
    3. Please mark your post [SOLVED] if it has been answered satisfactorily.


    Old Scottish Proverb...
    Luathaid gu deanamh maille! (Rushing causes delays!)

  3. #3
    Registered User
    Join Date
    09-06-2011
    Location
    Paris
    MS-Off Ver
    Excel 2003
    Posts
    23

    Re: Save all worksheets in a folder (incl subfolders) as separate files (w/o name conflict

    Hello Leith

    Many thanks indeed for your help. I'd like to take you up on your offer about other file types, as I have numerous ".XLS" mixed in.

    Unfortunately, I'm getting a "Run-time error '438': Object doesn't support this property or method" at the line "For Each Wks In Wkb" in the middle of this section of the code. Please could you assist? Thanks.

    Please Login or Register  to view this content.

  4. #4
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,258

    Re: Save all worksheets in a folder (incl subfolders) as separate files (w/o name conflict

    Hello 1819,

    You should never see this error in VBA. This indicates something is wrong with either the VBA environment or Excel. You should defragment your disk and registry and try it again.

  5. #5
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,258

    Re: Save all worksheets in a folder (incl subfolders) as separate files (w/o name conflict

    Hello 1819,

    My apologies for making you do all that work. I was a bit distracted with getting my daughter's cat to the vet for his surgery. When I read the post again, I realized my error.

    The code should be ...
    Please Login or Register  to view this content.

  6. #6
    Registered User
    Join Date
    09-06-2011
    Location
    Paris
    MS-Off Ver
    Excel 2003
    Posts
    23

    Re: Save all worksheets in a folder (incl subfolders) as separate files (w/o name conflict

    Hello Leith

    Absolutely no problem - hope the cat is all right.

    It works now. Many thanks. If you could spare a moment to show the adaptation for .XLS, I would be really grateful.

    Thanks.

  7. #7
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,258

    Re: Save all worksheets in a folder (incl subfolders) as separate files (w/o name conflict

    Hello 1819,

    The cat came through the surgery with no problem. Thanks for for your concern.

    Here is the code to add more filters to the macro...
    Please Login or Register  to view this content.

  8. #8
    Registered User
    Join Date
    09-06-2011
    Location
    Paris
    MS-Off Ver
    Excel 2003
    Posts
    23

    Re: Save all worksheets in a folder (incl subfolders) as separate files (w/o name conflict

    Hello Leith

    Well that's a relief - our friend's Siamese got through $9K in bills recently. Thank goodness they had insurance.

    Thanks for adapting the code. It's stumbling when it finds it is creating a duplicate file name. The debugger points to this line:

    Please Login or Register  to view this content.
    Can this possibly be set to allow a file to be created with a unique name?

    Many thanks.

  9. #9
    Registered User
    Join Date
    09-06-2011
    Location
    Paris
    MS-Off Ver
    Excel 2003
    Posts
    23

    Re: Save all worksheets in a folder (incl subfolders) as separate files (w/o name conflict

    This is now closed. Please reply to http://www.vbaexpress.com/forum/show...656#post325656

+ 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. [SOLVED] List All Changed Excel Files Today On Drive And Hyperlink (Incl. Subfolders)
    By alienware in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 08-10-2014, 03:18 AM
  3. VBA to save multiple worksheets as separate CSV files using name of worksheet
    By titushanke in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 09-20-2012, 08:08 AM
  4. Counting files in folder including subfolders also and folder size
    By mido609 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 07-12-2012, 03:26 PM
  5. [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