Microsoft Office Excel has encountered a problem and needs to close

J

jerry

Hi,

we have recently upgraded from Office 2003 to Office 2007. Our users
are using some Excel files created in Excel 2003. These files contain
some code in VBA.
There is a CLOSE button on the form and when they hit on that close
button excel is araising the following exception. The code behind
close button is simple (ActiveWorkbook.Close SaveChanges:=False).

"Microsoft Office Excel has encountered a problem and needs to close.
We are sorry for the inconvenience."

I dont get this error when 2003 is used.

How can I solve this problem?

Thanks
 
J

Joel

I suspect that 2007 doesn't lkike to close while a dialog box is open. The
code needs to be modified to close the form and then close the workbook. I
would have to see more of the code but there should be a .show which opens
the form. When the ofrm closes it returns to the instrustion after the show.
The close needs to be put after the show.
 
J

jerry

The code is very simple --

When the user clicks on a button in the worksheet, the form opens.
There is another button called close. The code for that is

Application.DisplayAlerts = False 'confirmation to save the worksheet
will not be received.
ActiveWorkbook.Close False
 
J

Joel

Try closing the userform before using the the exit button and see if the
problem disappears. If that is the case then you need to automate the
closing of the Userform when the user press the button called closed.

try unloading the userform before closing the workbook

Unload UserForm1
 
J

jerry

once the form is unloaded the control is no more in the code. thus the
workbook wont close. I want the workbook to close fully.
 
J

Joel

I didn't realize from your descripion the button to close the workbook was on
the form.

You should have something like this

Private Sub CommandButton1_Click()
userform1.show
End Sub

change this to the following. Remove the close from inside the userform.

Private Sub CommandButton1_Click()
userform1.show
ActiveWorkbook.Close False
End Sub
 

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