Command works from debug but not normally

M

Merlynsdad

I'm a problem closing a workbook without saving it. I'm closing another
workbook, then the current workbook with the following code in Private Sub
workbook_close():

Workbooks("real1.xls").Close False
Me.Close False

When I step through the code or run the code from the debug toolbar this
works. But when I use File Exit or the X, it asks whether or not I want to
save both files. I don't want to save either. What am I doing wrong?
 
D

Dave Peterson

Are you disabling events before you try to close the file with the code?

If no, then when that me.close line executes, it'll fire the
workbook_beforeClose event again (you meant _beforeclose, right???)

application.enableevents = false
Workbooks("real1.xls").Close False
Me.saved = true 'this will stop the "save?" prompt
'if you closed it, then the procedure would stop at that line
'(when the Me closes)
'and never get to this next line.
application.enableevents = true
 
M

Merlynsdad

The enableevents=false stops it from asking if I want to save the "real1.xls"
file, but I'm still getting a prompt asking if I want to save the
activeworkbook (mgrquery.xls) even with the me.saved=true. I need to kill
that prompt as well. And yes, I meant "beforeclose". Thanks.
 
D

Dave Peterson

The enableevents line doesn't suppress the prompt for reall.xls, that's what the
line:
Workbooks("real1.xls").Close savechanges:=False
line does.

Are you making any other changes to the workbook that holds the code
(mgrquery.xls) after that line?

I don't work with Queries to know, but guessing by the name, maybe it's a query
problem????
 
M

Merlynsdad

I solved my own problem. I was exiting the file but not Excel, so I added

application.displayalerts=false
application.quit

and now no matter how my users exit the file they won't see prompts asking
if they want to save. Thanks for the previous help.
 
D

Dave Peterson

What happens if they have other workbooks open?

Do you really want to try to force them to quit?

(That never seemed fair to me (a typical user).)
 
M

Merlynsdad

This is a re-write of the only Excel program they normally use, so dumping
them out shouldn't be a problem. Most of their stuff is custom built. Thanks
for the help.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top