Solved

'Can't enter break mode at this time'  Can this dialog be trapped in VBA

Posted on 2002-07-03
15
1,331 Views
Last Modified: 2012-05-07
Is there a way to trap the VBA error message 'Can't enter break mode at this time' when running a VBA macro. A dialog box is displayed which require entry of Continue, End etc from a user. Can this be trapped by VBA? For the moment, I don't care why it's happening, as I've found that taking the Continue option allows the process to go through to end. What I want to do is trap it and branch round it, until I can fix the cause, so that the user is not aware of it happening.  'On error'  doesn't detect the problem.

0
Comment
Question by:macbone2
  • 7
  • 5
  • 2
  • +1
15 Comments
 
LVL 16

Expert Comment

by:Richie_Simonetti
Comment Utility
Humm, try to see is there is time problem. Run your macros with F8 and see...
0
 
LVL 2

Author Comment

by:macbone2
Comment Utility
Richie, thanks but I've stepped thru these macros with F8 many times, and when the crucial line is encountered, the 'Can't enter break mode...' message occurs. I can't trap or control it. even Stop doesn't have any effect.
I don't understand the reference to time problem.

macbone2
0
 
LVL 16

Expert Comment

by:Richie_Simonetti
Comment Utility
Some times methods and functions are called asyncronius so they return to caller without finish the task yet. Then, when you try to use the resulting data (or whatever you use) that data isn't available yet. Due to that i did think it was a time problem.
Could you post the code here?
0
 
LVL 2

Author Comment

by:macbone2
Comment Utility
RICHIE
Thanks for taking the time. The code is below, it's all straight forward stuff that I've used before. There seems to be something odd about this workbook. I took the book over and rebuilt it, and added masses of VBA. Odd things were happening with it like Application.ScreenUpdating = False had no effect.
When I looked at Addins, Solver was there, and I wondered if that was a problem, so removed it. Made no diff but wonder if nasties left behind??

 In the code below, if I comment out the first line that causes the break mode message, the next line cause it. Even if the 'Sheets("Week 1").Move'   code
is executed on its own, the message is displayed. Sorry this is so long. BTW I've tried moving the essential sheets and VBA to a new book, but when I try to reopen it, I get an application error 'Access violation' (I tried this 3 times)


Sub SaveWeek2()
Dim FILEWeek1 As String, FldrName As String
ActiveSheet.Unprotect password:="jen"
Application.DisplayAlerts = False
Application.EnableEvents = False
Sheets("Week 1").Select
On Error Resume Next
'* Get rid of all the buttons,combo boxes etc
ActiveSheet.Shapes.SelectAll
Selection.Cut   '** THIS LINE CAUSES 'Can't enter break mode...
On Error Resume Next
'* Delete event handlers from Week 1 sheet
'this identifies the sheet code and deletes
Call DeleteCtlVBA    '** THIS ROUTINE CAUSES 'Can't enter break mode...
'* move the sheet to a new book and save
On Error Resume Next
Sheets("Week 1").Move   '** THIS LINE CAUSES 'Can't enter break mode...
FILEWeek1 = Range("HtlName") & " FORECAST " & _
Format(Range("c1").Value, "YYYY-MM-DD")
Stop
FldrName = "C:\Forec938\"
On Error Resume Next
MkDir FldrName
Stop
FILEWeek1 = FldrName & FILEWeek1
    On Error Resume Next
    ActiveWorkbook.SaveAs FILEWeek1
    If Err.Number <> 0 Then
    MsgBox "Error " & Err.Number & Chr(13) & "Description  " & Err.Description
    End If
ActiveWorkbook.Close
End Sub
0
 
LVL 16

Expert Comment

by:Richie_Simonetti
Comment Utility
Well, i don't get that error.
Could you try this?
Sub SaveWeek2()
dim sh as worksheet
Dim FILEWeek1 As String, FldrName As String

set sh= thisworkbook.sheets("Week 1")
with sh
     .Unprotect password:="jen"
     Application.DisplayAlerts = False
     Application.EnableEvents = False
On Error Resume Next
'* Get rid of all the buttons,combo boxes etc
     .Shapes.SelectAll
end with
     Selection.Cut   '** THIS LINE CAUSES 'Can't enter break mode...
...
....
0
 
LVL 2

Author Comment

by:macbone2
Comment Utility
Richie, No, I don't get the error in any other workbook either. This is the only place I've encountered it.
I tried the alternative code you kindly provided, but it makes no difference, at the line    'Selection.Cut'     the message still occurs.

0
 
LVL 16

Expert Comment

by:Richie_Simonetti
Comment Utility
Well, i think that i know what happens here.
Before do any deletion of controls and code, save the resultant file. After that remove not wanted controls and code from that file and save it again.
It appears like we are trying to delete objects and code that are use at the time of deletion.
0
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
LVL 2

Author Comment

by:macbone2
Comment Utility
Hi Richie, Thanks for the suggestion, I've tried all combinations of moving, copying or deleting sheets, controls and VBA code combined with saving before. In every case I always at some point come across the stumbling block of the warning message, so now i HAVE TO find a way of trapping the message, and forcing the macro to continue. Any ideas?

Thanks again for your time

Geoff
0
 
LVL 16

Expert Comment

by:Richie_Simonetti
Comment Utility
Well, we could manage a test.
I could do a little workbook trying to do what i already explained: would you like that i send it to you?
0
 
LVL 2

Author Comment

by:macbone2
Comment Utility
Yes that might be helpful Richie. My email address is geoff.mckeown@gordona.demon.co.uk.
One small problem is that I go on vacation tomorrow (Thursday) early, and won't be back until 31 July, but please post it and i will respond ASAP

Thanks
Geoff
0
 
LVL 16

Expert Comment

by:Richie_Simonetti
Comment Utility
OK. I am working at.
Happy Vacations!
0
 
LVL 44

Expert Comment

by:bruintje
Comment Utility
Hi guys any chance of getting this back on track? Haven't seen you for a long while Richie ...!... you didn't give up on EE i hope :)
0
 
LVL 16

Expert Comment

by:Richie_Simonetti
Comment Utility
Hi Bruintje! I have been very very busy for the pass month and just right know, i am working on an external project ($). No time to post "free" work as you could imagine.
Cheers
0
 
LVL 44

Expert Comment

by:bruintje
Comment Utility
Hello macbone2

this question is open for more then 2 months
time to clean up
if not stated otherwise

my recommendation will be
-PAQ and refund
-this will be finalized by an EE Moderator
-with no further update (23.11.2002)

PLEASE DO NOT ACCEPT THIS COMMENT AS ANSWER

HAGD:O)Bruintje
posted by ToolzEE v1.0
0
 
LVL 5

Accepted Solution

by:
Netminder earned 0 total points
Comment Utility
Per recommendation, points refunded and question closed.

Netminder
EE Admin
0

Featured Post

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

No matter the version of Windows you are using, you may have some problems with Windows Search running too slow or possibly not running at all. Before jumping into how you can solve this issue, just know there are many other viable alternative deskt…
This article will guide you to convert a grid from a picture into Excel format using Microsoft OneNote and no other 3rd party application.
The viewer will learn how to use a discrete random variable to simulate the return on an investment over a period of years, create a Monte Carlo simulation using the discrete random variable, and create a graph to represent the possible returns over…
Learn how to create and modify your own paragraph styles in Microsoft Word. This can be helpful when wanting to make consistently referenced styles throughout a document or template.

744 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now