Excel 2007 Craches when closing via macro code

C

Corey

When i close a workbook through code such as :

sub button6()
Application.DisplayAlerts = False
ActiveWorkbook.Save
ActiveWorkbook.Close
Application.DisplayAlerts = True
End Sub

and

Private Sub Workbook_BeforeClose(Cancel As Boolean)
On Error Resume Next
Dim WB As Workbook
For Each WB In Application.Workbooks
Debug.Print WB.Name
If WB.Name <> ThisWorkbook.Name Then
If WB.Windows(1).Visible = True Then Exit Sub
End If
Next
Sheets("Navigation Sheet").Select
Application.Quit
End Sub


I get an ERROR, prompts me to \send report to MS or not.

If i open Excel and a blank sheet and then exit excel i get No error, so it seem to be ONLY when
exiting via code.

How do i fix this?


Corey....
 
M

Mark Ivey

Give something like this a try...




Sub button6()

Application.DisplayAlerts = False
ActiveWorkbook.Save
Application.Quit

End Sub
 
D

David J Richardson

Corey said:
When i close a workbook through code such as :

ActiveWorkbook.Close

I get an ERROR, prompts me to \send report to MS or not.

Have you installed the service pack that came out last week? One of the
bugs fixed could be paraphrased as "legit VBA code that worked fine in
Excel 2003 caused nonsensical crashes in Excel 2007 until we fixed it a
year later with this service pack".

I had similar crashes using the line you mention (though not every time
it was invoked, or in every place it existed in the code) until last
week's upgrade.
 
D

Darren Hill

David said:
Have you installed the service pack that came out last week? One of the
bugs fixed could be paraphrased as "legit VBA code that worked fine in
Excel 2003 caused nonsensical crashes in Excel 2007 until we fixed it a
year later with this service pack".

I had similar crashes using the line you mention (though not every time
it was invoked, or in every place it existed in the code) until last
week's upgrade.

I've had a lot of these kind of crashes, so I'm hoping SP1 fixes it.

Another thing I've seen: with a workbook with lots of macros open, and
the VBE open, I can walk away, leave it doing nothing, and return to
find it has crashed ("Do you Excel to attempt to recover your work?").
This doesn't happen if I don't have the VBE open.

Has anyone seen anything like this, and does SP1 fix it?

Thanks, Darren
 

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