Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Shaun E on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How do I properly close? 2

Status
Not open for further replies.

newprogamer

Programmer
Sep 22, 2004
107
US
Hello Everyone,

I am having two problems (that I am aware of) when closing my program.

First, I have created an exit command button on a VB form. When the exit button is clicked, I need to close the VB form, Excel, and the Excel workbook. The code below leaves Excel open; however, it closes the workbook and the VB form. How do I properly close everything that is open when the exit button is clicked.

Code:
Private Sub cmdExitSpec_Click()
    Workbooks.Close
    Unload Me
    End
End Sub

Second, if I click the X control button in the top right corner to close my VB form, when I try to reopen the program, I receive a message box to "Recover my work and restart Microsoft Excel". Do I need to add some type of code to ensure it is closing properly when the X control button is clicked?

Any help would be appreciated. Thanks is advance!
New programmer
 
Hi
For the code you could try

unload me
application.quit

dunno about your second question, unfortunately.

;-)
If a man says something and there are no women there to hear him, is he still wrong? [ponder]
How do I get the best answers?
 
The second question regards the Query_Close event. There are other things you could do with it, but if you just want to disable the little X, a run through the FAQs for the this forum will tell you exactly how to do that. You can modify it to make sure it also close things they way you want.

Just a reminder that the FAQs are, in fact, a very helpful area of this place.

Look here: faq707-2697

Gerry
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top