Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 276
Default Easiest way to Debug Code

I have a Workbook that has a great many Procedures and Userforms c/w code.

I use a Clip Art 'EXIT' sign as a way to Save/Close the workbook with simple Code.

But about 50% of the Time the Code Saves then Closes, and Crashes, giving me a 'Do you want to Send Report' Option.

The other 50% of the time there is No issues.

The code to Close when clicking the Clip Art Image is:
~~~~~~~~~~~~~
Sub Picture6_Click()
Application.DisplayAlerts = False
ActiveWorkbook.Save
If Workbooks.Count 1 Then
ActiveWorkbook.Close
Else
Application.Quit
End If
Application.DisplayAlerts = True
End Sub
~~~~~~~~~~~~~


My question is, I think the problems IS NOT the above code, but nothing else executes on exit, so how can I Debug the workbook to fit the problem ?
--
Corey ....
The Silliest Question is generally
the one I forgot to ask.
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 257
Default Easiest way to Debug Code

First, maybe this is too obvious but when it bombs do you have more than one
workbook open? and when it works correctly do you have only one? The below
code looks to me like it checks to see whether you have only one workbook
open, and if you do to close it but otherwise to just get out of Excel
without saving anything, which surely isn't what you really wanted.

But to answer your question, everyone probably has his own favorite methods
but mine in this case would be to put a breakpoint on the below Sub
statement, then go back to your spreadsheet and click the Exit sign so you
can step through the procedure one step and a time; this'll tell you at least
which statement is leading to the abend, which surely is a good hint as to
what's going wrong.

But you probably already knew this, so either I misunderstood your question
or you're really new to VBA debugging - and if the latter is the case, the
above explanation went by 'WAY too fast. If so, say so here (or contact me
by email if you prefer) and we'll talk more about how to do those things like
"set breakpoints", "step through" your code one statement at a time and other
even neater things.

--- "Corey" wrote:
I have a Workbook that has a great many Procedures and Userforms c/w code.
I use a Clip Art 'EXIT' sign as a way to Save/Close the workbook with simple
Code. But about 50% of the Time the Code Saves then Closes, and Crashes,
giving me a 'Do you want to Send Report' Option. The other 50% of the time
there is No issues.

The code to Close when clicking the Clip Art Image is:
~~~~~~~~~~~~~
Sub Picture6_Click()
Application.DisplayAlerts = False
ActiveWorkbook.Save
If Workbooks.Count 1 Then
ActiveWorkbook.Close
Else
Application.Quit
End If
Application.DisplayAlerts = True
End Sub

My question is, I think the problems IS NOT the above code, but nothing else
executes on exit, so how can I Debug the workbook to fit the problem ?

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 276
Default Easiest way to Debug Code

Bob,
Thanks for the reply.
The code i posted actually saves the Workbook Before it checks If more than
1 WorkBook is opened.

I set a BreakPoint at the Sub posted, and it stopped there.
I Clicked continue, and it Closed as expected.
There was another WorkBook open also.

I tried the same with No other WorkBooks opened, and got the same result.

I guess i will have to keep trying to notice WHAT is Different/Consistant
when it does crash.


Corey....

"Bob Bridges" wrote in message
...
First, maybe this is too obvious but when it bombs do you have more than
one
workbook open? and when it works correctly do you have only one? The
below
code looks to me like it checks to see whether you have only one workbook
open, and if you do to close it but otherwise to just get out of Excel
without saving anything, which surely isn't what you really wanted.

But to answer your question, everyone probably has his own favorite
methods
but mine in this case would be to put a breakpoint on the below Sub
statement, then go back to your spreadsheet and click the Exit sign so you
can step through the procedure one step and a time; this'll tell you at
least
which statement is leading to the abend, which surely is a good hint as to
what's going wrong.

But you probably already knew this, so either I misunderstood your
question
or you're really new to VBA debugging - and if the latter is the case, the
above explanation went by 'WAY too fast. If so, say so here (or contact
me
by email if you prefer) and we'll talk more about how to do those things
like
"set breakpoints", "step through" your code one statement at a time and
other
even neater things.

--- "Corey" wrote:
I have a Workbook that has a great many Procedures and Userforms c/w
code.
I use a Clip Art 'EXIT' sign as a way to Save/Close the workbook with
simple
Code. But about 50% of the Time the Code Saves then Closes, and Crashes,
giving me a 'Do you want to Send Report' Option. The other 50% of the
time
there is No issues.

The code to Close when clicking the Clip Art Image is:
~~~~~~~~~~~~~
Sub Picture6_Click()
Application.DisplayAlerts = False
ActiveWorkbook.Save
If Workbooks.Count 1 Then
ActiveWorkbook.Close
Else
Application.Quit
End If
Application.DisplayAlerts = True
End Sub

My question is, I think the problems IS NOT the above code, but nothing
else
executes on exit, so how can I Debug the workbook to fit the problem ?



  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 257
Default Easiest way to Debug Code

Yeah, sounds like it. I'm not familiar with DisplayAlerts; any chance that
by turrning it off you're missing some vital datum? Just a thought.

--- "Corey" wrote:
The code i posted actually saves the Workbook Before it checks If more than
1 WorkBook is opened. I set a BreakPoint at the Sub posted, and it stopped there.
I Clicked continue, and it Closed as expected. There was another WorkBook open
also. I tried the same with No other WorkBooks opened, and got the same result.
I guess i will have to keep trying to notice WHAT is Different/Consistant
when it does crash.

--- "Bob Bridges" wrote:
....maybe this is too obvious but when it bombs do you have more than
one workbook open? and when it works correctly do you have only one? The
below code looks to me like it checks to see whether you have only one
workbook open, and if you do to close it but otherwise to just get out of Excel
without saving anything, which surely isn't what you really wanted.

--- "Corey" wrote:
I have a Workbook that has a great many Procedures and Userforms c/w
code. I use a Clip Art 'EXIT' sign as a way to Save/Close the workbook with
simple Code. But about 50% of the Time the Code Saves then Closes, and
Crashes, giving me a 'Do you want to Send Report' Option. The other 50% of
the time there is No issues.

The code to Close when clicking the Clip Art Image is:
~~~~~~~~~~~~~
Sub Picture6_Click()
Application.DisplayAlerts = False
ActiveWorkbook.Save
If Workbooks.Count 1 Then
ActiveWorkbook.Close
Else
Application.Quit
End If
Application.DisplayAlerts = True
End Sub

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 947
Default Easiest way to Debug Code

ActiveWorkbook.Close

Is the active workbook the one with the running code?

--
Dana DeLouis

<snip


Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
debug code mohavv Excel Discussion (Misc queries) 1 November 27th 07 09:56 PM
Please help debug this code! Heliocracy Excel Programming 1 October 23rd 07 10:04 PM
Debug Error in Code Karen McKenzie Excel Discussion (Misc queries) 2 May 18th 07 04:25 PM
Need help with code debug please justme Excel Programming 2 January 4th 07 06:09 AM
Code hangs Excel ... Why? ... and how can i debug?? Simon May Excel Programming 1 January 17th 05 06:22 AM


All times are GMT +1. The time now is 08:10 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"