ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Debug.Print statement causes Excel crash (https://www.excelbanter.com/excel-programming/448889-debug-print-statement-causes-excel-crash.html)

[email protected]

Debug.Print statement causes Excel crash
 
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.

joeu2004[_2_]

Debug.Print statement causes Excel crash
 
wrote:
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.



Auric__

Debug.Print statement causes Excel crash
 
joeu2004 wrote:

wrote:
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.

--
Be yourself by yourself. Stay away from me.

[email protected]

Debug.Print statement causes Excel crash
 
On Saturday, June 15, 2013 1:06:07 PM UTC+2, wrote:
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.


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."

Walter Briscoe

Debug.Print statement causes Excel crash
 
In message of
Sat, 15 Jun 2013 23:48:43 in microsoft.public.excel.programming,
writes
On Saturday, June 15, 2013 1:06:07 PM UTC+2, wrote:
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.


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."


Thanks for trying again. I did not bother reporting my failure to make
Excel 2003 crash with your earlier description.

I am sorry to report that I tried what you said and Excel did not crash.
When I followed up the opening with Alt+F11 to open the Visual Basic
Editor, I see the code:
Private Sub Auto_Open()
Debug.Print , "Test"
End Sub
and an Immediate window showing:
Test

Do you have a second machine on which to repeat the test with a clean
Excel installation?

I am afraid I can only say what a developer used to say to me, "It works
on my machine." ;)
--
Walter Briscoe

joeu2004[_2_]

Debug.Print statement causes Excel crash
 
wrote:
wrote:
The crash occurs only when a 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 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
MediaFi http://www.mediafire.com
FileFactory: http://www.filefactory.com
FileSavr: http://www.filesavr.com
RapidSha 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.


[email protected]

Debug.Print statement causes Excel crash
 
On Saturday, June 15, 2013 1:06:07 PM UTC+2, wrote:
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.


I tested on a separate laptop with original installed Windows XP and Office 2003 which also caused Excel to crash. Download test Excel doc on https://skydrive.live.com/redir?resi...l7TZ9 8yLgSg0

joeu2004[_2_]

Debug.Print statement causes Excel crash
 
wrote:
Download test Excel doc on
https://skydrive.live.com/redir?resi...l7TZ9 8yLgSg0


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?


[email protected]

Debug.Print statement causes Excel crash
 
On Saturday, June 15, 2013 1:06:07 PM UTC+2, wrote:
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.


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 error and retain the formatting for example in Debug.Print " ", <remainder
Thanks!


All times are GMT +1. The time now is 02:59 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com