Logo 
Search:

MS Office Forum

Ask Question   UnAnswered
Home » Forum » MS Office       RSS Feeds

Error Message "Can't enter break mode at this time"

  Asked By: Madison    Date: Sep 17    Category: MS Office    Views: 3801
  

I have some VBA code which copy a speardsheet and then delete it.

Private Sub CommandButton1_Click()
Sheets("Sheet1").Copy Before:=Sheets(1)

Dim i As Integer
i = 1
Do While (i <= Sheets.Count)
If Sheets(i).Name = "Sheet1" Then
i = i + 1
Else
Application.DisplayAlerts = False
Sheets(i).Delete
Application.DisplayAlerts = True
End If
Loop
End Sub

However, when I test this, it halts with the error message "Can't
enter break mode at this time", with options Continue,End,Help and
the usual Debug button is greyed out.
If I select 'Continue', all the sheets except "Sheet1" will be
deleted as I desired.
If I select 'End',the current spreadsheet is deleted but I can't
procede with any more code in the subroutine.

Any one can help me on this problem? ‚hwant to find the problem of
the codes, or add some codes to select 'Continue' automatically so
that user will not see the popup msg.

Share: 

 

5 Answers Found

 
Answer #1    Answered By: Ethan Evans     Answered On: Sep 17

I think your best bet is to step through the code  using f8 and see what
happens. set a watch on i so you know where the sub thinks it is.

It is a good idea to comment out the Application.DisplayAlerts lines while
you are debugging the code.

 
Answer #2    Answered By: Komal Mohammad     Answered On: Sep 17

I tried your macro and it seems to run Ok except ---

it copies sheet1  to Sheet1(1) then it deletes Sheet1(1) because it is not
called "Sheet1" so the copy  exercise seems a bit pointless.

You end  up with only the original sheet1 in the workbook.

 
Answer #3    Answered By: Chau Tran     Answered On: Sep 17

I think the problem  has to do with the fact that you're trying to step it
through.

Take your breakpoints off and let it run.

Worked fine for me on 2003 once I did this.

"Can't enter  break mode" includes having the VBE get control so you can
single step. (No real idea why it has problems with debugging this code,
but remember that deleting a worksheet also deletes its code  module from the
VBE, so it must be having trouble with the fact that the programming scope
has changed, even while it's trying to show it to you in debug  mode.)

 
Answer #4    Answered By: Viheke Fischer     Answered On: Sep 17

I finally find  the problem  is caused by X-control button  on the
original sheet. When I replace all X-control button with Form
button, the problem is solved!

 
Answer #5    Answered By: Jeanette Greene     Answered On: Sep 17

I don't really think this is a problem  at all, it is
just VB's way of telling you the routine that follows
cannot be stepped through, it must be ran. I've had
this happen a few times & the only debug  is to verify
the results - you won't have the luxury of watching
step by step.

 
Didn't find what you were looking for? Find more on Error Message "Can't enter break mode at this time" Or get search suggestion and latest updates.




Tagged: