By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
434,655 Members | 1,860 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 434,655 IT Pros & Developers. It's quick & easy.

Activeworkbook.close doesn't close

P: 4
I'm trying to use the activeworkbook.close VBA function. It works fine if I've made any changes to the workbook. However, if I haven't made any changes to the workbook, then it doesn't close.
Dec 31 '13 #1
Share this Question
Share on Google+
8 Replies

Expert Mod 5K+
P: 5,397
Please show us the code.
Remember to format it using the [CODE/] formatting button in the toolbar.
Dec 31 '13 #2

P: 4
Expand|Select|Wrap|Line Numbers
  1. Sub aMoveClose2()
  3.     ActiveWorkbook.Close
  5. End Sub
Dec 31 '13 #3

Expert Mod 5K+
P: 5,397
Change to
Expand|Select|Wrap|Line Numbers
  1. ThisWorkbook.Close savechanges:=False
this will close the calling workbook and discard changes.

Activeworkbook, sure you can use this, however, I can call code from one workbook to close another (grin); thus, you have to check which book is active before calling close on it.
Dec 31 '13 #4

P: 4
Thank you for the advice. However, I want it to specifically close the WB I'm working in. The macro will be in my Personal macros WB, but I want it to close the WB I'm working in. It will do other things as well surrounding the close action, but I'm still working on just getting it to close.

If I'm understanding it, the following code will close the Personal WB if it's stored there.
Expand|Select|Wrap|Line Numbers
  1. ThisWorkbook.Close savechanges:=False
Dec 31 '13 #5

Expert 5K+
P: 8,634
Along the lines of what zmbd was saying, would the following work for you?
Expand|Select|Wrap|Line Numbers
  1. Dim wb As Excel.Workbook
  3. For Each wb In Application.Workbooks
  4.   If wb.Name = ActiveWorkbook.Name Then
  5.     Workbooks(wb.Name).Close
  6.   End If
  7. Next
Jan 1 '14 #6

Expert Mod 5K+
P: 5,397
Do you see the level of detail you gave in reply to my post?

If you had fully explained what you were doing, as you did in your second post, then I would have offered code more alone the lines of ADezii's

The code I gave you will close the workbook in which it is stored, doesn't matter if it is in a class, standard, or the "thisworkbook" module.
Jan 1 '14 #7

P: 4
Thanks to both of you. Yes, zmbd, in the future I will give more detail. Sorry about that. Also, the issue just stopped happening on it's own. Now the ActiveWorkbook function does exactly what I would expect it too as shown in my code above. Weird. Don't know if I had another macro or something blocking it.
Jan 1 '14 #8

Expert Mod 15k+
P: 31,487
I would just point out, at this stage, that ActiveWorkbook & ThisWorkbook are different animals. The former is whichever one is open and active currently, while the latter is the workbook associated with the code itself. Different - but frequently confused.
Jan 1 '14 #9

Post your reply

Sign in to post your reply or Sign up for a free account.