+ Reply to Thread
Results 1 to 4 of 4

Need to close opened workbook after copying sheet(3) and repeat process using loop.

  1. #1
    Registered User
    Join Date
    03-24-2013
    Location
    NY
    MS-Off Ver
    Excel 2013
    Posts
    7

    Need to close opened workbook after copying sheet(3) and repeat process using loop.

    The macro that I have loops through a directory and opens all files and copies sheet(3) from each file and places it into the current workbook as separate sheets. The problem I am having is closing the just opened workbook. When the macro is done I have all of these opened workbooks. I tried using activeworkbook.close but it wants to close the workbook that I want to stay open. The one that the macro is running in. I could run separate code that loops through all of the open workbooks and closes all of them but the one I want left open. I was hoping that it could be done within the same loop.

    Please Login or Register  to view this content.

  2. #2
    Forum Expert Alf's Avatar
    Join Date
    03-13-2004
    Location
    Gothenburg/Mullsjoe, Sweden
    MS-Off Ver
    Excel 2019 and not sure I like it
    Posts
    4,758

    Re: Need to close opened workbook after copying sheet(3) and repeat process using loop.

    Try replacing
    Please Login or Register  to view this content.
    with
    Please Login or Register  to view this content.
    You will also need to add a dim statement i.e.
    Please Login or Register  to view this content.
    Alf

  3. #3
    Registered User
    Join Date
    03-24-2013
    Location
    NY
    MS-Off Ver
    Excel 2013
    Posts
    7

    Re: Need to close opened workbook after copying sheet(3) and repeat process using loop.

    Thanks you that worked great.

  4. #4
    Forum Expert Alf's Avatar
    Join Date
    03-13-2004
    Location
    Gothenburg/Mullsjoe, Sweden
    MS-Off Ver
    Excel 2019 and not sure I like it
    Posts
    4,758

    Re: Need to close opened workbook after copying sheet(3) and repeat process using loop.

    Thanks for feedback and rep!

    Alf

+ 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