Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Can't Enter Break Mode in Excel 1

Status
Not open for further replies.

cameronfraser

Programmer
May 18, 2001
13
0
0
US
In Excel 2000 While in break mode and stepping through a macro, the following message appears when I hit a line of code:
"Can't Enter Break Mode at this time". The only options I get are the buttons "Continue", "End" or "Help". The "Debug" button is inactive. (As usuall the Help button provides no useful help).

Here are the lines of code that generate this message:

Application.DisplayAlerts = False
Workbooks(Trust_Workbook).Worksheets("Template
PVIT").Delete
Application.DisplayAlerts = True

The code deleting the worksheet causes the "Can't Enter Break Mode at this time" message"

When just these 3 lines of code are run on their own the Can't break message does not occur.

What is happening? What situation in the design and running of a macro could cause this problem?

Thanks


What is happening?
 

cameronfraser:

The error always occurs. When you run the code the line Application.DisplayAlerts = False does not show you the error because the error is an Alert and you've turned Alerts off. When you step through the code this line of code is ignored and Alerts are shown so you can check for errors in each line of code.

Hope that helps, LoNeRaVeR
 
When I am stepping through the macro I step into the line:

Application.DisplayAlerts = False

and then I step into the line:

Workbooks(Trust_Workbook).Worksheets("Template
PVIT").Delete

That is when I get the "Can't Enter Break Mode at this time" message. I get the message after the display alerts were turned off. I don't think the display alerts has anything to do with the problem.

I think the line that deletes the worksheet is causing the macro to not allow stepping into each line. I can continue on with the macro, but I just can't step into each line and I can't control break the execution of the macro.

I am at a loss as to why the abiltiy to step into each line is lost when that worksheet is deleted?
 

cameronfraser:

Comment out the Application.DisplayAlerts = False and run the code again. My hunch is that you'll still get the error.

Let me know, LoNeRaVeR
 
Yup, I still get the error when I comment out display alerts.

I think that something is happening earlier in the macro to cause the ability to step through the macro to stop. This could be more than a code problem, but something to do with how objects are used or modules called.

Do you have any ideas?

Thanks for the help.
 
cameronfraser:

The reason you get the error is not due stepping through the Application.DisplayAlerts = False code. You received the error when you commented out that line, the same as stepping through it, because the error lies in the next line. Quotes are required around the Workbooks Name.

Workbooks("Trust_Workbook").Worksheets("Template PVIT").Delete

That should correct the problem. The most common reason Alerts are turned off when deleting sheets is so that the end user won't be prompted with whether they would like to delete the sheet. Just make sure there is a sheet left in the workbook or you'll still have problems.

HTH, LoNeRaVeR
 
LoNeRaVeR, Thank you for the help.

I tried your suggestion, but it didn't work. I got the runtime error 'subscript out of range'. I cannot put quotes around Trust_Workbook in the line

Workbooks(Trust_Workbook).Worksheets("Template PVIT")
.Delete


because Trust_Workbook is not the name of the workbook, Trust_Workbook is a string variable assinged the name of a workbook.

As I mentioned before, I think that something is happening earlier in the macro to cause the ability to step through the macro to stop. This could be more than a code problem, but something to do with how objects are used or modules called.

Have you ever had this problem? Do you know of anyone else who has had this problem?
 
cameronfraser:

I thought about the fact that Trust_Workbook might be a string after entering my last post. When you step through the code are you seeing that Trust_Workbook is always assigned a name? That would be cause for an error. LoNeRaVeR
 
Trust_Workbook is assigned a name before the line:
Workbooks("Trust_Workbook").Worksheets("Template PVIT").Delete
is executed. The execution of this line works, but the ability to step through the macro stops working.

I even did a test where I stepped through a small macro that assigned Trust_Workbook and then executed the above delete line. This test worked and the ability to step through the macro kept on working. I didn't get my message "Can't Enter Break Mode at this time" .


 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top