Debug.Print statement causes Excel crash


B

bpv.hamdorff

After some search effort I found the cause for an Excel crash. Just in case you experience the same this is what I discovered:

In Excel 2003, 2007 (and later?) the statement

Debug.Print , "test"

causes Excel to crash. There is an <empty> expression in front of the comma. The crash occurs only when a piece of VBA is executed without the Visual Basic editor window opened.
 
Ad

Advertisements

J

joeu2004

After some search effort I found the cause for an Excel crash.
Just in case you experience the same this is what I discovered:
In Excel 2003, 2007 (and later?) the statement
Debug.Print , "test"
causes Excel to crash. [....] The crash occurs only when a piece
of VBA is executed without the Visual Basic editor window opened.

I think there is more to this than meets the eye.

No problem for me with XL2003 using either of the following with the VBA
window closed.

Function myfunc()
Debug.Print , "test"
End Function

Sub mysub()
Debug.Print , "test"
End Sub

The function is invoked with the formula =myfunc(). The subroutine is
executed by pressing alt-F8, then clicking on Run.
 
A

Auric__

joeu2004 said:
After some search effort I found the cause for an Excel crash.
Just in case you experience the same this is what I discovered:
In Excel 2003, 2007 (and later?) the statement
Debug.Print , "test"
causes Excel to crash. [....] The crash occurs only when a piece
of VBA is executed without the Visual Basic editor window opened.

I think there is more to this than meets the eye.

No problem for me with XL2003 using either of the following with the VBA
window closed.

Function myfunc()
Debug.Print , "test"
End Function

Sub mysub()
Debug.Print , "test"
End Sub

The function is invoked with the formula =myfunc(). The subroutine is
executed by pressing alt-F8, then clicking on Run.

Same here, Excel 2007 and Excel 2010. I'd suggest that the OP try stepping
through the code that crashes and see what's happening there. It generally
takes some extraordinary measures to get Excel to crash.
 
B

bpv.hamdorff

After some search effort I found the cause for an Excel crash. Just in case you experience the same this is what I discovered: In Excel 2003, 2007 (and later?) the statement Debug.Print , "test" causes Excel to crash. Thereis an <empty> expression in front of the comma. The crash occurs only whena piece of VBA is executed without the Visual Basic editor window opened.

Try This: Add a module with the following sub:

Private Sub Auto_Open()
Debug.Print , "Test"
End Sub

Save and close the Excel document; Close the Excel application.
Then open the Excel document from the Windows Explorer and allow the macro to run. Excel will crash: "Microsoft Office Excel has encountered a problemand needs to close. We are sorry for the inconvenience."
 
J

joeu2004

Try This: Add a module with the following sub:
Private Sub Auto_Open()
Debug.Print , "Test"
End Sub
Save and close the Excel document; Close the Excel application.
Then open the Excel document from the Windows Explorer and
allow the macro to run. Excel will crash: "Microsoft Office
Excel has encountered a problem and needs to close. We are
sorry for the inconvenience."

Previously, you said "without the Visual Basic editor window open". We
cannot execute a __Private__ Sub directly without the VBE window open. (The
operative word is "directly".)

I suggest that you upload an example Excel file to a file-sharing website,
then post the URL for us to download it. The following is a list of some
free file-sharing websites; or use your own.

Box.Net: http://www.box.net/files
Windows Live Skydrive: http://skydrive.live.com
MediaFire: http://www.mediafire.com
FileFactory: http://www.filefactory.com
FileSavr: http://www.filesavr.com
RapidShare: http://www.rapidshare.com

But I suspect we cannot duplicate the problem. The problem is probably with
your computer environment. I suggest that try Office Repair. If that does
not remedy the problem, try uninstalling and reinstalling Office.
 
B

bpv.hamdorff

After some search effort I found the cause for an Excel crash. Just in case you experience the same this is what I discovered: In Excel 2003, 2007 (and later?) the statement Debug.Print , "test" causes Excel to crash. Thereis an <empty> expression in front of the comma. The crash occurs only whena piece of VBA is executed without the Visual Basic editor window opened.

I tested on a separate laptop with original installed Windows XP and Office2003 which also caused Excel to crash. Download test Excel doc on https://skydrive.live.com/redir?resid=71CADE8D32227A66!164&authkey=!AGdl7TZ98yLgSg0
 
Ad

Advertisements

J

joeu2004


I overlooked the significance of the fact that it is an Auto_Open macro.

(The same error occurs when I use a Workbook_Open event macro.)

I only get the error when I open it using Excel 2007, not Excel 2003 (sp3)
and not Excel 2010.

The error goes away when I remove the leading comma in the Debug.Print list.
That is:

Debug.Print "Test"

instead of

Debug.Print , "Test"

The function of the leading comma is put "Test" at the first tabstop. I was
able to effect the same function without error with the following statement:

Debug.Print vbTab & "Test"

Does that work for you?
 
Ad

Advertisements

B

bpv.hamdorff

After some search effort I found the cause for an Excel crash. Just in case you experience the same this is what I discovered: In Excel 2003, 2007 (and later?) the statement Debug.Print , "test" causes Excel to crash. Thereis an <empty> expression in front of the comma. The crash occurs only whena piece of VBA is executed without the Visual Basic editor window opened.

I'm happy that you were able to replicate the error. I posted this message because it might benefit others. Of course I found a way to avoid the errorand retain the formatting for example in Debug.Print " ", <remainder>
Thanks!
 

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