excel crash when using macro to close workbook

already

Board Regular
Joined
Nov 11, 2008
Messages
179
Hi

In my last thread I thought that a conflict between macros causes to crash excel (2007) . But this is not true.

I have the following strange problem. A simple macro 'ActiveWorkbook.Close' causes excel to crash if I use it with a button on my sheet (a form). When I run the macro via developer > macros > run
the macro runs as expected. Even if a run the macro with alerts (thanks to jproffer) the problem persist.

Thanks in advance for your help

Kind regards

Al
 

Excel Facts

Get help while writing formula
Click the italics "fx" icon to the left of the formula bar to open the Functions Arguments dialog. Help is displayed for each argument.
In what way is it "Crashing?" , and can you post your code please.
 
Last edited:
Upvote 0
Al

As Sykes has said post your code - also please try to stick with the original thread, or at least post a link to it.

I think I know which thread you are referring back to.

But even in that thread you didn't post the relevant code.:)
 
Upvote 0
Hi Guys

Sorry for the confusion

1/ In what way is it "Crashing?" , and can you post your code please.

- Microsoft Office Excel has encountered a problem and needs to close. We are sorry for the inconvenience.
- my code even with following simple code excel crashes
'ActiveWorkbook.Close'

2/ I didn't stick with the original thread (436658)
because the problem was not the conflict between macros but the using of a button for the closing macro

Kind regards

Al
 
Upvote 0
Al
1. Where's the code kept? Is it in the button's _click event, a different module or what?
2. Do you have more code which runs in this workbook? If so, could you post it please.
3 Is there any code which runs in the Workbook_close event?
4.
A simple macro 'ActiveWorkbook.Close' causes excel to crash if I use it with a button on my sheet (a form).
Do you mean that this is a "Forms" type button, or is it a button inserted onto a userform?
5. Do you get a "Save Workbook?" prompt after the button's pressed?

I'm sure we'll be able to sort this (probably Norie will, actually !!!) but it seems we need more information on what's happening inthe background when this sheet's running. It seems that something's conflicting when the button's pressed, so I'm trying to establish what else is going on just before runtime, or at the moment the button's pressed.
 
Last edited:
Upvote 0
Hi Sykes

Hope this will gives you enough feedback ....

* With this code in module1 of the workbook excel crashes

Sub crash()
ActiveWorkbook.Close
End Sub

* with this code in module1 of the workbook excel and windows crashes

Sub crash()
Application.DisplayAlerts = False
ThisWorkbook.Save
ThisWorkbook.Close
Application.DisplayAlerts = True
End Sub

but only if I'm using a button on my sheet inserted via form control

Initial other code was in the same work book but I 'm testing with a new workbook with only this code in it

No prompt appear only an hourglass appears in an excel window than a white screen than a message 'Microsoft Office Excel has encountered a problem and needs to close. We are sorry for the inconvenience' or if I use
the second macro a windows reboot

Please note again that when I run the macros without the button everything works fine

Kind regards

Al
 
Upvote 0
Al

I'm running Vista and Office 2007. When I re-create your scenario it all works fine, so there's something unstable in your application by the sounds of it.
I can only think of one thing here:
Try assigning the code to an ActiveX CommandButton instead (from the ActiveX Controls part of the Insert menu). I find these controls better for manipulating data and properties anyway. To access the button's code module, in design mode, right-click the button and select "View code."

Did running the code in a new workbook work, or not?
 
Upvote 0
Hi Sykes

Yes it did the work. Many thanks for your help!!!!

But it still strange because I have many workbooks with macros assigned to buttons that causes no problems

Have a nice WE

Al
 
Upvote 0
Al - Like you said - strange.

Anyway, glad you're sorted.
 
Upvote 0

Forum statistics

Threads
1,214,976
Messages
6,122,543
Members
449,089
Latest member
davidcom

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top