записал два макроса, а потом попытался склеить их и подкорректировать в редакторе. Помогите!!!!! |
|
Юрий М Модератор Сообщений: 60567 Контакты см. в профиле |
Процедура приостановлена. Нажмите кнопочку Reset. |
{quote}{login=The_Prist}{date=15.07.2011 12:45}{thema=}{post}Надо остановить выполнение макроса и уже только после этого что-то пытаться делать.{/post}{/quote} гляньте, очень прошу, может увидите где ошибка. |
|
{quote}{login=}{date=15.07.2011 12:48}{thema=Re:}{post}{quote}{login=The_Prist}{date=15.07.2011 12:45}{thema=}{post}Надо остановить выполнение макроса и уже только после этого что-то пытаться делать.{/post}{/quote} гляньте, очень прошу, может увидите где ошибка.{/post}{/quote} просто с ВБА не работал и не знаю как определить где ошибка, а может вообще он не будет выполнятся. Остановить каким образом? При запуске просто возвращает в редактор и пишет эту ошибку ..на конкретное место не указывает |
|
Юрий М Модератор Сообщений: 60567 Контакты см. в профиле |
Зачем в данном случае текст макроса? Просто остановите его выполнение. |
{quote}{login=Юрий М}{date=15.07.2011 12:54}{thema=}{post}Зачем в данном случае текст макроса? Просто остановите его выполнение.{/post}{/quote} в конце вот такой кусочек .Caption = «Сумма по полю тт с ммл» и пишет ошибку |
|
Юрий М Модератор Сообщений: 60567 Контакты см. в профиле |
Не лишний, а наоборот — не хватает! |
{quote}{login=Юрий М}{date=15.07.2011 01:09}{thema=}{post}Не лишний, а наоборот — не хватает!{/post}{/quote} Спасибо!!!! эту ошибку вроде исправил. With Workbooks.OpenFilename:=»C:Documents and Settingsanalitik.ЛЕЛИЧЕВАРабочий столвременные файлыmml» Не скажите что не так? |
|
Юрий М Модератор Сообщений: 60567 Контакты см. в профиле |
Может там такого файла нет? |
{quote}{login=The_Prist}{date=15.07.2011 01:43}{thema=}{post}Скажем — учить Вам VBA надо. Спасибо за помощь, очень благодарен всем кто ответил. А учить ВБА мне надо,- согласен с Вами. вот таким образом и пытаюсь учить. |
|
Юрий М Модератор Сообщений: 60567 Контакты см. в профиле |
Загляните в «Копилку». Дорожку туда можно найти в Правилах. |
ххх Гость |
#12 15.07.2011 14:48:46 {quote}{login=Юрий М}{date=15.07.2011 02:29}{thema=}{post}Загляните в «Копилку». Дорожку туда можно найти в Правилах.{/post}{/quote} спасибо |
mazza
New Member
- Joined
- Jun 26, 2007
- Messages
- 6
-
#1
hi,
I’m at my new work and i’ve got a small job from my boss, he wants me to correct a function in a excel macro. I’m quite new to vba programming so its a hard task for me. When i klick on the button to activate the macro i get the error Can’t execute code in break mode. As far as i’ve understood this is because there is something else going on at the same time.
This is the begning of the function, it continues futher down but the debug says the problem is here(the bold underlined sentance). Is the problem here or is it somewhere else in the gaint excel document, its very big.:
Function IndividX()
Dim JobLd(256)
With Application
.Calculation = xlManual
.MaxChange = 0.001
End With
ActiveWorkbook.PrecisionAsDisplayed = False
Sheets(«ResourcePlanW»).Range(«A7:IV6000»).ClearContents
EndRowP = Sheets(«ResourcePlan»).Columns(«A»).Find(«EndRow»).Row — 1
FirstRowP = 8
FirstClmnRP = Sheets(«ResourcePlanX»).Rows(4).Find(«Datum»).Column + 2
Sheets(«ResourcePlanW»).Range(«A8:IV6000»).Select
With Selection.Font
‘.Name = «Arial»
.FontStyle = «Normal»
‘.Size = 10
‘.Strikethrough = False
‘.Superscript = False
‘.Subscript = False
‘.OutlineFont = False
‘.Shadow = False
‘.Underline = xlUnderlineStyleNone
.ColorIndex = xlAutomatic
End With
Selection.Interior.ColorIndex = xlNone
NxtClmn = 7
Excel Facts
Last used cell?
Press Ctrl+End to move to what Excel thinks is the last used cell.
JazzSP8
Well-known Member
- Joined
- Sep 30, 2005
- Messages
- 1,227
- Office Version
-
- 2013
- 2010
- Platform
-
- Windows
-
#2
Hi — Welcome to the board
Does this happen as soon as you open the workbook?
IE: Open Workbook >> Click Button >> Error Message?
Or is it possible you have been debugging it and tried to run it again?
If the latter is the case you need to stop the code by pressing the Stop button at the top of the VBE (Play / Pause / Stop).
Other than that, I’ve never seen that before ..
Jonmo1
MrExcel MVP
- Joined
- Oct 12, 2006
- Messages
- 44,061
-
#3
Welcome to the board.
1. Can’t execute code in break mode means that some code previously errored, and you clicked Debug. VBA is now in a Paused Mode. It can’t start a new code until you either resolve the error and resume the previous code, or STOP the previous code that errored. In the VBA window, you should see a Stop and a Play button (like those of a CD Player) on the toolbar. Press Play to try to Resume the code that priviously failed, or press Stop to END the previous code that failed.
2. As for the problem, If that’s the line highlighted, my first guess would be that the Sheet ResourcePlanW either does not exist, or is hidden. If it doesn’t exist, well, you need to make it exist, or change the sheetname the code is trying to select. If it’s just hidden, you can either manually unhide it, or put this line before the highlighted line.
Sheets(«ResourcePlanW»).Visible = True
Jonmo1
MrExcel MVP
- Joined
- Oct 12, 2006
- Messages
- 44,061
-
#4
Actually, I can guess the sheet does exist and is just hidden. Because previous lines referred to the sheet without selecting it. So it must exist.
You can change that code to NOT select the sheet, the same way the previous code did.
Try replacing the code with this..
Code:
Function IndividX()
Dim JobLd(256)
With Application
.Calculation = xlManual
.MaxChange = 0.001
End With
ActiveWorkbook.PrecisionAsDisplayed = False
Sheets("ResourcePlanW").Range("A7:IV6000").ClearContents
EndRowP = Sheets("ResourcePlan").Columns("A").Find("EndRow").Row - 1
FirstRowP = 8
FirstClmnRP = Sheets("ResourcePlanX").Rows(4).Find("Datum").Column + 2
With Sheets("ResourcePlanW").Range("A8:IV6000").Font
'.Name = "Arial"
.FontStyle = "Normal"
'.Size = 10
'.Strikethrough = False
'.Superscript = False
'.Subscript = False
'.OutlineFont = False
'.Shadow = False
'.Underline = xlUnderlineStyleNone
.ColorIndex = xlAutomatic
End With
Sheets("ResourcePlanW").Range("A8:IV6000").Interior.ColorIndex = xlNone
NxtClmn = 7
mazza
New Member
- Joined
- Jun 26, 2007
- Messages
- 6
-
#5
Thanks for the help guys, a friend of mine simced to know the problem aswell, i had to stop and then when i started the macro it worked fine.
Anyway i’ll be asking more questions later as they pop up, now i’ll return to studdy some more vba, cya later
Similar threads
I am trying to write a simple macro to add 1 to the cell’s current value:
Sub add()
MsgBox Selection.Value
Selection.Value = Selection.Value + 1
End Sub
I receive the following error message when I click a (numeric) cell and try to run the macro:
Cannot Execute in Break Mode
What am I missing?
asked Feb 18, 2013 at 10:45
2
You are already executing a macro and somehow stopped its execution (e.g. due to an unhandled error or because you pressed Ctrl—Break during the execution). In this state, you cannot execute another macro.
In the Visual Basic Editor, you need to press the Stop button:
Then you can run the macro.
If you want to understand where the current execution is stopped, right click the code and select Show Next Statement. If you then press F8 you can step through the code. F5 continues the execution.
answered Feb 18, 2013 at 10:54
Peter AlbertPeter Albert
16.8k4 gold badges66 silver badges88 bronze badges
2
And you should check if the value in the cell is numeric. Example
Sub add()
If IsNumeric(Selection.Value) Then
Selection.Value = Selection.Value + 1
Else
MsgBox ("Not a value selected")
End If
End Sub
answered Feb 18, 2013 at 11:25
Ben WelmanBen Welman
3012 silver badges4 bronze badges
Sub Lower()
Range ("e3"), Value = Range("e3"), Value - 1
End Sub
Sub Higher()
Range ("e3"), Value = Range("e3"), Value + 1
End Sub
Marc
3,8854 gold badges23 silver badges37 bronze badges
answered Dec 30, 2016 at 7:34
What is the Error “Can’t Execute Code in Break Mode”?
There are three modes in which the VBA IDE can operate: Run mode, Break mode, or Design mode.
The IDE is in design mode when you are writing code or designing a form. Run mode occurs when a procedure is running. Break mode is entered when a running procedure stops because of either an error in the code or a deliberate act by the programmer to run the code line by line to easily identify the source of an error.
In this article, you are going to learn how to run a VBA code in break mode and understand the origin of the error “can’t execute code in break mode.”
Running a Procedure in Break mode
As we earlier mentioned, Break mode pauses the execution of a code, and allows you to edit it. In break mode properties and values are held so that you can analyses their current state. Break mode can be activated by the following ways:
1. Select Break from the Run menu or Click + Break or press the Pause button while the procedure is running.
2. Insert a Stop statement in your code.
3. Insert a Breakpoint in your code. There are many ways through which you can insert a breakpoint in a code. The easiest one are: click in the light grey area to the left of the line where you want a break or you place the cursor on the desired line and hit on the F9 key.
4. Use Step into on the debug toolbar or press F8 to execute one line of code at a time starting from the location of the break.
Note that the VBA IDE goes automatically on a Break mode when it encounters an error while running a procedure. In this case, it will stop the execution of the procedure at the problematic code and highlight that code in yellow.
The Cause of the “Can’t Execute Code in Break Mode” Error and How to Fix It
One of the most common reason for this error is that you tried to run code from the Macro dialog box when the same code that was launched in Visual Basic was suspended in break mode accidentally, intentionally or because of an error in the coding. To solve that, you should continue running the suspended code, or terminate its execution before running the code from the Macro dialog box.
Example
In this example we are going to write a small procedure to fill cells A1 to A50 with values from 1 to 50.
Sub Fillcells() Dim i As Integer For i = 1 To 50 Range("A & i).Value = i Next i End Sub
Note that our procedure/Macro is called “Fillcells
”. This code will run without stop to then end, but this is not our intention. What we want is to insert a break in the code and try running it through the Macro dialog box to see the result.
To do that we first have to add a Stop statement or a break point as follows:
Sub Fillcells() Dim i As Integer For i = 1 To 50 Range("A & i).Value = i Stop Next i End Sub
With this second code you need to hit the Run button fifty times! (just press it once) To write all the values. For our example, just press it once to get to this:
Now that we are in a break mode as seen by the highlighted line in yellow let’s try to run the same procedure named Fillcells from the Macro dialog box.
Once you press the Run button, you will get the “Cannot execute code in break mode as seen below, just because the procedure still running in VBA is in Break mode. So you have to stop that one before coming back to the Macro dialog box to run the macro.
Hope it was not too difficult to understand.
When your program generates a runtime error, a dialog box similar to the one shown in Figure 7.4 is displayed.
The runtime error dialog box.
The runtime error dialog box.
Selecting the Debug option will load the VBA IDE and display the program in Break Mode. While in Break Mode, program execution is paused and can be stepped through one line at a time to closely examine factors such as order of code execution and the current values stored within variables. The line of code that generated the error will be highlighted as shown in Figure 7.5.
The Debug toolbar
Toggle breakpoints
The Debug toolbar
Toggle breakpoints
The VBA IDE in Break Mode.
Step Into
Debug windows
Step Into
The VBA IDE in Break Mode.
Debug windows
To intentionally enter Break Mode, insert a breakpoint at the desired location in the program using the Debug menu item or Debug toolbar (select from the View menu) in the VBA IDE (refer to Figure 7.5). You can also toggle a breakpoint by clicking the left margin of the code window next to the line of code at which you want program execution to pause, or by pressing F9.
Insert break points at locations in code where bugs are suspected or known to exist and then run the program. Break Mode is entered when program execution proceeds to a line of code containing a breakpoint. At this time, you have the option of resetting the program, stepping through the program one line at a time, or continuing normal operation of the program. While in Break Mode, the value currently stored in a variable can be checked by holding the mouse cursor over the name of that variable. Logic errors are often caused by code that assigns the wrong value to a variable. Break Mode can help locate the code that creates these errors.
Another useful debugging method is stepping through code while in Break Mode. Use Step Into on the Debug toolbar, or press F8, to execute one line of code at a time starting from the location of the break. The order of program execution can be verified, and values stored within variables checked as code execution proceeds one line at a time.
Continue reading here: The Immediate Window
Was this article helpful?
Хотя это может не совсем ответить на Can't execute...
ошибка, можете ли вы попробовать, если следующий код выдает ту же ошибку? Я считаю, что Select
использование в вашем коде вызывает это, поскольку я испытал почти то же самое в прошлом…
Sub nmMod()
Set Start = Sheets("Winput").Range("A10")
EndCol = Start.End(xlToRight).Column
EndRow = Start.End(xlDown).Row
Start.Resize(EndRow, EndCol).Copy
Sheet2.Range("A1").PasteSpecial xlPasteAll 'mock action, change as necessary
End Sub
Лучше всего избегать любого выбора, насколько это возможно. Подражая Select
действие намного медленнее и порождает другие проблемы (т.е. они могут отменить copy
, испортить действия, особенно с участием фигур и т. д.). Не будет большим сюрпризом, если это будет причиной самой ошибки.