VBA Excel Break Points and Stop do not work
vba code checker
allow access special keys
Any idea why inserting break points and stop no longer stops my vba code from running?
The code runs ok all the way to the end (I tested it) but ignores break points and Stop.
Also step into just makes the code run in it's entirety, ignoring break points and stops.
When I close the workbook where the issue seems to originate from the same issue occurs in other macro workbooks.
if I completely close excel and re-open it with a normally working macro workbook the issue doesn't occur until I re-open the problem work book.
I added breakpoints on:
TotP1 = 0
of the following code:
Option Explicit Private Country As String Private Measure As String Private P1 As String Private P2 As String Private TotP1 As Double Private TotP2 As Double Sub VennDisplayIt() Dim SI() As String Dim SICount As Integer Dim x As Integer Dim OSh As Worksheet Dim BrandListBox As Object Dim VennGroup As Shape TotP1 = 0 TotP2 = 0 Set OSh = ThisWorkbook.Sheets("Venn") Set BrandListBox = OSh.OLEObjects("BrandListBox").Object ReDim SI(2, 0) For x = 0 To BrandListBox.ListCount - 1 If BrandListBox.Selected(x) = True Then 'If UBound(SI) < 4 Then ReDim Preserve SI(2, UBound(SI, 2) + 1) SI(1, UBound(SI, 2)) = BrandListBox.List(x) SI(2, UBound(SI, 2)) = x + 1 'End If End If Next x If UBound(SI, 2) < 2 Then BrandListBox.Selected(BrandListBox.ListIndex) = True Exit Sub ElseIf UBound(SI, 2) > 4 Then BrandListBox.Selected(BrandListBox.ListIndex) = False Exit Sub End If For x = 1 To UBound(SI, 2) OSh.Range("o8").Offset(x, 0).Value = SI(1, x) OSh.Range("o8").Offset(x + 5, 0).Value = SI(1, x) Next x For x = UBound(SI, 2) + 1 To 4 OSh.Range("o8").Offset(x, 0).Value = "" OSh.Range("o8").Offset(x + 5, 0).Value = "" Next x SICount = UBound(SI, 2) For x = 1 To OSh.Shapes.Count If Right(OSh.Shapes(x).Name, 5) = "Group" Then If LCase(OSh.Shapes(x).Name) = SICount & "waygroup" Then Set VennGroup = OSh.Shapes(x) OSh.Shapes(x).Visible = True Else OSh.Shapes(x).Visible = False End If End If Next x For x = 1 To SICount VennGroup.GroupItems.Item(SICount & "WayBrand" & x).DrawingObject.Text = SI(1, x) Next x Country = ThisWorkbook.Sheets("Venn").Range("D4").Value Measure = ThisWorkbook.Sheets("Venn").Range("E32").Value P2 = ThisWorkbook.Sheets("Venn").Range("E31").Value P1 = ThisWorkbook.Sheets("Selections").Range("B5").Value End Sub
I've never heard of
Stop not working, but I've heard about and experienced the breakpoint thing many times. When you compile VBA, it creates a p-code, which is used by the interpreter. You have the VBA syntax layer that you can see and the p-code layer that you can't see. When breakpoints stop working, it's because the p-code was corrupted. I don't know how or why it happened, but it did.
The fix is to export, remove, and reimport all of your modules. Exporting them creates a .bas file (plain text, really). When you re-import, the p-code is regenerated from scratch. If you have more than a couple of modules, get CodeCleaner (free add-in) and it will export and reimport automatically.
Break points not working, In the same sheet break points do work for other events. I've tried A funny thing too: the event is meant to call a macro but it is not (and it did a week ago). I had the problem with breakpoints not stopping the code. I was In the example shown below, the macro will only break when a cells value is equal to 25. The below image shows how you can pause your code before you run another VBA macro. Below shows how you can pause the code right after it has completed going through a large loop.
Just to 'second' Tibo's comment: I had a problem where I had a form with about 5 different subroutines. One of them (attached to a button event) would not stop when I set a breakpoint. in 10 years of VBA writing, I've never seen that happen. Interestingly, breakpoints worked on all of the other subroutines in that form. After much head-scratching and searching, I came upon this post and Tibo's comment. I added a "Stop" command to the affected subroutine, ran the procedure (it stopped as it should have) and then breakpoints began working again! Hope this helps someone in the future.
Breakpoint is not stopping code, I am trying to debug some code and have added several breakpoints to a Have I done something fundamentally wrong, I'm still a newbie at VBA? Stop 'Despite putting Stop here code does not appear to run when I click Use CRTL + BREAK to suspend execution at any point. You will be put into break mode and can press F5 to continue the execution or F8 to execute the code step-by-step in the visual debugger.
If the breakpoints are in your code, then the code should stop running as soon as it hits that line. Possible causes of your problem:
a) The code never gets to the Breakpoint. Seems highly unlikely seeing as you're breaking on the first line of your code. Maybe step through the sub (F8) just to check it's running as it should.
b) Your breakpoints have been wiped. Any line with a breakpoint should display as highlighted in red on your IDE. Your breakpoints can easily be wiped through, e.g. closing and opening the workbook (a screenshot would be really useful).
c) your workbook is broken in some way. It would be unlikely to break something as fundamental as stopping at breakpoints and still function normally. Are you sure your code is actually running?
Set and clear a breakpoint (VBA), You clear breakpoints when you no longer need them to stop execution. Breakpoints set in code are not saved when you save your code. I set a breakpoint in a subroutine and the execution of source code does not stop at that breakpoint. Execution continues as if breakpoint is not there. I can tell by having a MsgBox with a unique message after the breakpoint. I have done a Compact and Repair, Decompile, and other desparate acts. This seems almost impossible to believe. Why me?
If one of the settings is unchecked then breakpoints will not work. "File/options/Current database/Application options/use access special keys" should be checked
Setting Breakpoints and the VBA Stop Statement, One feature of breakpoints is that they are not saved wihen you close a VBA will run the code until it reaches the STOP statement, then allow If you have an event handler, for a quick test, you could put a 'Stop' in the event handler to stop like you are asking. If not you can put one in as already stated. Assertions are nice, I like them and use a lot of them - but here since you know the function and are working on this explicit problem a Stop should be good enough for your testing.
Just sharing a funny thing which happened to me in case it helps someone. The mistake I did was that I simply took someone's method code meant for workbook open event and pasted it on
Sheet1 excel object code area. So there was no possibility of
Workbook_Open method getting fired ever.
Private Sub Workbook_Open() Stop On Error Resume Next Call ActiveSheet.Worksheet_Activate On Error GoTo 0 End Sub
What I was supposed to do is paste this method after double clicking
ThisWorkbook node under
Microsoft Excel Objects in Project pane as shown below:
Note: Side effect of copy-pasting others code can be freaky at times.
Code Execution Has Been Interrupted – How To Fix That Annoying , You've written your Excel VBA application and everything's working fine, then for no I can only guess at this, not being a Microsoft Insider, but it seems to me that when of code will be highlighted to show that execution has stopped at that point. As the compiled vba code in the workbook probably has a hidden breakpoint By setting the VBA breaking point you can press the F5 key to run the macro code and your execution will be completed until the 26 th line and since we applied the breakpoint it will stop there. From that line onwards we can debug the code. Popular Course in this category
VBA Excel Break Points and Stop not working, I have never heard that Stop not working, but I have heard and experienced a breakpoint many times. When you compile VBA, it creates p-code that is used by I have found that going into task manager, then selecting excel, then view, refresh now several times, then exiting some times brings excel back out of a not responding condition. I believe this cycling between view and refresh now somehow gets it back on track.
Debugging VBA Code • My Online Training Hub, ActiveCell.Font.Bold = True End Sub A breakpoint is a line in your code where you tell VBA to pause and wait. To create a breakpoint you This works in a similar way to breakpoints, but are not not set. With a breakpoint Sometimes when we use any loop condition in VBA, it often happens that the code keeps on running without an end or break. To avoid this kind of situations it is recommended to use some breaks or exit functions by which we can exit from the loop with the measurable output from the macro.
VBA Debugging - Breakpoints, A breakpoint allows you to run your code and have it stop at a specific point before Since breakpoints are not saved within a file the stop command allows the
- Could you show the code and where the breakpoints are placed?
- I just added the code.
- I ran your code with a breakpoint on
TotP1 = 0and it broke there exactly as it should. So my guess is that there is indeed something corrupted in that workbook.
- @ExcelHero Ithink you may be right. It's crashed a few time recently. I'm ging to try and re-create it in a new workbook. I get the same probelm on two different machines so it seems to be the file rather than excel settings.
- Not only have I never experienced
Stop(as written in the code) not working, but whenever I'm having the (frequent) issue of breakpoints not breaking execution and/or code updates not showing on execution, adding a single
Stopresolves it instantaneously. Since there is no real written
Stopin @OliverHumphreys code, I wonder if he was actually talking about
Stopor thinking about
F9breakpoints / conditional breakpoints.
- Hi, It looks like it's C). I can't step through the code as that's part of the problem. however my break points are definitely in place and highlighted in red. the code is definitely running as I put a test right at the end to modify a cell and it worked. I've just transferred everything to a new workbook and it seems to be working ok for the time being.
- Okay, glad to be of help :)