+ Reply to Thread
Results 1 to 35 of 35

Close another workbook without saving

  1. #1
    Forum Contributor
    Join Date
    08-23-2011
    Location
    England
    MS-Off Ver
    Excel 2010
    Posts
    404

    Close another workbook without saving

    Hi all,

    I've tried to search for this but no joy as what I have found all use 'ThisWorkbook' as a starting point. If anyone is willing I require some simple code which points to a the workbook I want closing and then closes it without saving. The workbook will be open.

    I tried making that workbook active (.Activate) and then using ThisWorkbook.close but it didn't work.

    Can anyone help?

    (using 2010)

  2. #2
    Valued Forum Contributor xlbiznes's Avatar
    Join Date
    02-22-2013
    Location
    Bahrain
    MS-Off Ver
    Excel 2007
    Posts
    1,223

    Re: Close another workbook without saving

    Try this,


    Please Login or Register  to view this content.
    Happy Computing ,

    Xlbiznes.

    To show your appreciation please click *

  3. #3
    Forum Contributor
    Join Date
    08-23-2011
    Location
    England
    MS-Off Ver
    Excel 2010
    Posts
    404

    Re: Close another workbook without saving

    That is wonderful. Thank you very much. May I ask, I have the following at the end of my code which is intended to close and save the remaining workbook. Whilst it does this it still leaves Excel open (just with no workbooks open). Do you know how to close Excel completely?

    Please Login or Register  to view this content.

  4. #4
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643

    Re: Close another workbook without saving

    How did you create/open the workbook you want to close?
    If posting code please use code tags, see here.

  5. #5
    Valued Forum Contributor xlbiznes's Avatar
    Join Date
    02-22-2013
    Location
    Bahrain
    MS-Off Ver
    Excel 2007
    Posts
    1,223

    Re: Close another workbook without saving

    this will do the job.


    Please Login or Register  to view this content.
    Last edited by xlbiznes; 12-24-2013 at 06:06 AM.

  6. #6
    Forum Contributor
    Join Date
    08-23-2011
    Location
    England
    MS-Off Ver
    Excel 2010
    Posts
    404

    Re: Close another workbook without saving

    I'm afraid that didn't work xlbiznes. Excel is still 'open' (even though the workbooks are not) - I can still see the ribbon at the top of the screen.

  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,197

    Re: Close another workbook without saving

    Hi, plumby,

    maybe just save the workbook and then quit?
    Please Login or Register  to view this content.
    Please Login or Register  to view this content.
    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

  8. #8
    Forum Expert
    Join Date
    04-22-2013
    Location
    .
    MS-Off Ver
    .
    Posts
    4,418

    Re: Close another workbook without saving

    Please Login or Register  to view this content.
    I think

  9. #9
    Forum Contributor
    Join Date
    08-23-2011
    Location
    England
    MS-Off Ver
    Excel 2010
    Posts
    404

    Re: Close another workbook without saving

    Arrgh. Still no luck. This is what I'm running. The first bit closes another workbook without saving just fine. The last bit doesn't work - I need it to close AND SAVE the workbook (the one that has the macro) and then exit Excel completely.

    Please Login or Register  to view this content.

  10. #10
    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,197

    Re: Close another workbook without saving

    Hi, plumby,

    do you mind just using the code lines I sugested and not the ones you believe to be correct? Result should be as you wanted if you donīt close the workbook with code prior to closing Excel.

    Ciao,
    Holger

  11. #11
    Forum Contributor
    Join Date
    08-23-2011
    Location
    England
    MS-Off Ver
    Excel 2010
    Posts
    404

    Re: Close another workbook without saving

    Hi HaHoBe,

    Apologies, yes I seemed to have overlooked your code. I have tried it but Excel is still open. I have pasted my entire code with comments. It's the last two pieces which close a different workbook with saving (which works) and the very last routine which is meant to close the workbook which the macro is stored in (this is the one I cannot get to work).

    I have pasted all the code just in case there is something I am doing early on which is causing problems.

    Please Login or Register  to view this content.

  12. #12
    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,197

    Re: Close another workbook without saving

    Hi, Plumby,

    where is the difference between Workbooks("PBH slicers1.xlsm") and ThisWorkbook?

    From what I guess:
    Please Login or Register  to view this content.
    Ciao,
    Holger

  13. #13
    Forum Contributor
    Join Date
    08-23-2011
    Location
    England
    MS-Off Ver
    Excel 2010
    Posts
    404

    Re: Close another workbook without saving

    Thank you for this. It's very kind of you to take the time.

    I receive the 'Object doesn't support this property or method' on this line:

    Please Login or Register  to view this content.

  14. #14
    Forum Contributor
    Join Date
    08-23-2011
    Location
    England
    MS-Off Ver
    Excel 2010
    Posts
    404

    Re: Close another workbook without saving

    Sorry HaHoBe I forgot to answer your initial question. Yes, Workbooks("PBH slicers1.xlsm") and ThisWorkbook are the same thing.

  15. #15
    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,197

    Re: Close another workbook without saving

    Hi, Plumby,

    maybe set an object for the worksheet to which to copy?

    Ciao,
    Holger

  16. #16
    Forum Contributor
    Join Date
    08-23-2011
    Location
    England
    MS-Off Ver
    Excel 2010
    Posts
    404

    Re: Close another workbook without saving

    Sorry, I don't understand?

  17. #17
    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,197

    Re: Close another workbook without saving

    Hi, Plumby,

    I get the error as well, maybe try this altered code:
    Please Login or Register  to view this content.
    Ciao,
    Holger

  18. #18
    Valued Forum Contributor xlbiznes's Avatar
    Join Date
    02-22-2013
    Location
    Bahrain
    MS-Off Ver
    Excel 2007
    Posts
    1,223

    Re: Close another workbook without saving

    If application.quit is not doing the job ,

    We can force close excel using shell, try this.

    Please Login or Register  to view this content.

  19. #19
    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,197

    Re: Close another workbook without saving

    Hi, xlbizness,

    from where since that would imply improper coding (resolving the objects not in the opposite way of setting them) and that the workbook has been closed - definitely not from the code posted here, or am I wrong on that?

    Ciao,
    Holger

  20. #20
    Valued Forum Contributor xlbiznes's Avatar
    Join Date
    02-22-2013
    Location
    Bahrain
    MS-Off Ver
    Excel 2007
    Posts
    1,223

    Re: Close another workbook without saving

    @HaHoBe ,

    i am sorry i could not understand the context of your post.

  21. #21
    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,197

    Re: Close another workbook without saving

    Hi, xlbiznes,

    where in the code (like published in #17) should that sniplet be placed?

    Ciao,
    Holger

  22. #22
    Valued Forum Contributor xlbiznes's Avatar
    Join Date
    02-22-2013
    Location
    Bahrain
    MS-Off Ver
    Excel 2007
    Posts
    1,223

    Re: Close another workbook without saving

    @HaHoBe,

    We can place that after the application.quit statement.

    As we are trying to force close excel.This statement would be to the very end.

  23. #23
    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,197

    Re: Close another workbook without saving

    Hi, xlbizness,

    We can place that after the application.quit statement.
    There will be no workbook with the code available to run that code after Application.Quit for that instance Iīm afraid.

    Ciao,
    Holger

  24. #24
    Forum Contributor
    Join Date
    08-23-2011
    Location
    England
    MS-Off Ver
    Excel 2010
    Posts
    404

    Re: Close another workbook without saving

    I'm really confused. I wish I could just close Excel after the two workbooks have closed.

  25. #25
    Valued Forum Contributor xlbiznes's Avatar
    Join Date
    02-22-2013
    Location
    Bahrain
    MS-Off Ver
    Excel 2007
    Posts
    1,223

    Re: Close another workbook without saving

    HaHoBe,

    The issue is that application.quit is not doing what it is supposed to do. Hence taskkill is our last resort.

    According to @Plumby , excel is still active. On Excel 2007 application.quit closes excel completely.

  26. #26
    Forum Contributor
    Join Date
    08-23-2011
    Location
    England
    MS-Off Ver
    Excel 2010
    Posts
    404

    Re: Close another workbook without saving

    This is what Excel looks like after I run the macro.

    (xlbiznes I've yet to run your code - will do shortly)

    Excel screenshot.jpg

  27. #27
    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,197

    Re: Close another workbook without saving

    Hi, Plumby,

    you' re working with multipleinstances of Excel it seems but didnīt mention that (assumed was one instance from the poor information delivered).

    @xlbiznes:
    The issue is that application.quit is not doing what it is supposed to do.
    Who says so? Application.Quit can only quit one instance of Excel, and if TO doesnīt mention multiple instances that it still does the job. And again: no chance with the code supplied.

    Ciao,
    Holger

  28. #28
    Forum Contributor
    Join Date
    08-23-2011
    Location
    England
    MS-Off Ver
    Excel 2010
    Posts
    404

    Re: Close another workbook without saving

    Apologies for the poor information.

  29. #29
    Valued Forum Contributor xlbiznes's Avatar
    Join Date
    02-22-2013
    Location
    Bahrain
    MS-Off Ver
    Excel 2007
    Posts
    1,223

    Re: Close another workbook without saving

    @HaHoBe,

    the op said so ? We are talking in context to what the OP is facing.

  30. #30
    Valued Forum Contributor xlbiznes's Avatar
    Join Date
    02-22-2013
    Location
    Bahrain
    MS-Off Ver
    Excel 2007
    Posts
    1,223

    Re: Close another workbook without saving

    @HaHoBe ,

    Even the 1st instance is not closed, if you can see the image which the @Plumby has posted.

    @Plumby,How many instances of excel are running when you are running this macro ?

  31. #31
    Valued Forum Contributor xlbiznes's Avatar
    Join Date
    02-22-2013
    Location
    Bahrain
    MS-Off Ver
    Excel 2007
    Posts
    1,223

    Re: Close another workbook without saving

    @Plumby,

    did you try the shell command ?

    Please Login or Register  to view this content.

  32. #32
    Forum Contributor
    Join Date
    08-23-2011
    Location
    England
    MS-Off Ver
    Excel 2010
    Posts
    404

    Re: Close another workbook without saving

    Ok guys this is what happens.

    I have no workbooks open.
    I then open one workbook (PBH slicers1.xlsm) by double clicking it, that sets off a Workbook Open Event macro which opens in turn this - Post Book.xls. When it is finished no other workbooks will be ever be open as I plan on running it at 6am in the morning using Task Scheduler.
    At the end of the macro I then need to:
    • Close and save PBH slicers1.xlsm
    • Close and NOT save Post Book.xls
    • Quit Excel (2010)

  33. #33
    Forum Contributor
    Join Date
    08-23-2011
    Location
    England
    MS-Off Ver
    Excel 2010
    Posts
    404

    Re: Close another workbook without saving

    I'll try now...

  34. #34
    Forum Contributor
    Join Date
    08-23-2011
    Location
    England
    MS-Off Ver
    Excel 2010
    Posts
    404

    Re: Close another workbook without saving

    Just tried it and it works!

  35. #35
    Valued Forum Contributor xlbiznes's Avatar
    Join Date
    02-22-2013
    Location
    Bahrain
    MS-Off Ver
    Excel 2007
    Posts
    1,223

    Re: Close another workbook without saving

    Great and thank you for the reps.

+ 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. Close workbook without saving after msg box
    By RebeccaEllis in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 10-22-2012, 08:41 AM
  2. Close a workbook without saving
    By preciouslife73 in forum Excel General
    Replies: 2
    Last Post: 01-14-2012, 08:16 PM
  3. How do I close a workbook witout saving changes
    By plunkettyplunk in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 07-12-2010, 05:24 AM
  4. Saving:workbook close
    By DRANDON in forum Excel General
    Replies: 1
    Last Post: 07-28-2006, 02:15 PM
  5. Saving VBA project on workbook close
    By Eric Fingerhut in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 07-17-2006, 09:45 PM

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