INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Jobs

Code to close down excel application not working properly

Code to close down excel application not working properly

(OP)
I am currently using VBA code to close excel, rather than several steps. Originally the code worked as expected. Now it closes but gives this error code. "Microsoft Excel has stopped working. A problem caused the program to stop working correctly. Please close the program. Here is the current codes. Code #1 closes excel when not on the home page.

CODE --> VBA

Sub Exit_Referals()
Dim MsgBoxResult As Long

 MsgBoxResult = MsgBox("Would you like to Exit the Referral Workbook?" & vbCr, _
 vbYesNo)

 If MsgBoxResult = vbNo Then
 Exit Sub
 ElseIf MsgBoxResult = vbYes Then
 Sheets("TOC").Select
Application.Quit
Workbooks.Close
 End If
End Sub 
Code #2 closes excel from the home page.

CODE --> VBA

Sub TOC_Exit_Referals()

Dim MsgBoxResult As Long

 MsgBoxResult = MsgBox("Would you like to Exit the Referral Workbook?" & vbCr, _
 vbYesNo)

 If MsgBoxResult = vbNo Then
 Exit Sub
 ElseIf MsgBoxResult = vbYes Then
 Application.Quit
Workbooks.Close
 End If
End Sub 
I am hoping that you Geniuses, can figure out what is happening & how to fix it. This old boy is at wits end with this particular batch of code.

RE: Code to close down excel application not working properly

How can you first quit excel and next close workbooks?
Quit application without closing workbooks, excel will do it for you. Some comments to your code:
- if you have unsaved workbooks, save them first or close individually without saving changes or set Saved property to True,
- if any of the workbooks has BeforeClose or other event procedure firing when you close workbook, the code will be called too,
- you do not have to select "TOC" sheet, it will not be saved unless ather code saves workbook later.

combo

RE: Code to close down excel application not working properly

(OP)
I failed to mention that the normal save request comes up. If there has been new data entered, then save chosen & the data saved. TOC is used when excel is exited from any sheet other than TOC (Table of Contents). TOC is the home page for that particular excel app, & with multiple users, you want one common page to open too.

RE: Code to close down excel application not working properly

How many workbooks are closed? Are all saved (you can test it by adding End statement before Application.Quit and close workbooks manually after quitting procedure)?
You can remove Workbooks.Close from your code. What about my question about event procedures?

combo

RE: Code to close down excel application not working properly

(OP)
Just one workbook is saved at a time. The procedures were added at user requests. I did look at what you mentioned prior to coming up with the current code. The code just started acting stupid recently. Up till last week there were no issues

RE: Code to close down excel application not working properly

Quote (Frank)

The code just started acting stupid recently. Up till last week there were no issues

So what was changed/added in the code last week? Before the app started 'acting stupid'?

Have fun.

---- Andy

There is a great need for a sarcasm font.

RE: Code to close down excel application not working properly

(OP)
Strangely nothing.

RE: Code to close down excel application not working properly

How are either Exit Referals procedures called?

Did you remove the Application.Quit statement from both procedures?

Skip,

glassesJust traded in my OLD subtlety...
for a NUance!tongue

RE: Code to close down excel application not working properly

(OP)
Yes. There was no change. I did it on the home page (TOC).

RE: Code to close down excel application not working properly

(OP)
I just learned something just now. The problem is only with one workbook. I am getting the impression that I may just have to live with the problem.

RE: Code to close down excel application not working properly

(OP)
This is an update to the problem. It happens sporadically, so I will just have live with the issue. Thanks for your help.

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Resources

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close