Break point equivalent

User avatar
Don Wells
5StarLounger
Posts: 689
Joined: 27 Jan 2010, 16:45
Location: Ottawa, Ontario, Canada

Break point equivalent

Post by Don Wells »

    Is there a VBA Command equivalent that will act like a breakpoint? A breakpoint that doesn't disappear when the file is closed and reopened.
    I have been using a message box for tthis feature during code development; but when it fires I am unable to edit either the target document or the code while the code is stopped.
Regards
Don

User avatar
Doc.AElstein
BronzeLounger
Posts: 1499
Joined: 28 Feb 2015, 13:11
Location: Hof, Bayern, Germany

Re: Break point equivalent

Post by Doc.AElstein »

Hello Don ..... easy one ....
Stop

Code: Select all

Sub StopIt()   '        Break point equivalent       https://eileenslounge.com/viewtopic.php?p=268543#p268543
' Doing stuff
' Doing stuff
'
 Stop          '       Breakpoint Command: The  Stop  Statement     You can place Stop statements anywhere in procedures to suspend execution. Using the Stop statement is similar to setting a breakpoint in the code. The Stop statement suspends execution, but unlike End, it doesn't close any files or clear variables, unless it is in a compiled executable (.exe) file.                                            https://docs.microsoft.com/en-us/office/vba/language/reference/user-interface-help/stop-statement                                                                     Hi there, nice to see you here in this nice peacefull place. Hope you are well!  :)
'  Carry on after this from the VB Editor with a run ( F5 key )  or  carry on in step mode with key  F8
End Sub
( Stop statement )

Alan
I am having difficulty logging in with this account just now.
You can find me at DocAElstein also

User avatar
HansV
Administrator
Posts: 78475
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: Break point equivalent

Post by HansV »

You might also like Debug.Assert. It acts like a conditional breakpoint. The syntax is

Code: Select all

    Debug.Assert condition
The code will continue to run as long as condition evaluates to True, but it will pause when condition evaluates to False.

Example:

Code: Select all

Sub Test()
    Dim a As Long
    Dim b As Long
    a = 5
    For b = 1 To 10
        ' Some code here
        ' ...
        Debug.Assert b <> a
    Next b
End Sub
When you run the Test macro, it will pause when b = 5, for then the condition b <> a is NOT true.
Best wishes,
Hans

User avatar
Don Wells
5StarLounger
Posts: 689
Joined: 27 Jan 2010, 16:45
Location: Ottawa, Ontario, Canada

Re: Break point equivalent

Post by Don Wells »

Thank you Alan and Hans. Just what I wanted.
Regards
Don