ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   OnTime code error "can't execute code in break mode" (https://www.excelbanter.com/excel-programming/372442-ontime-code-error-cant-execute-code-break-mode.html)

tskogstrom

OnTime code error "can't execute code in break mode"
 
Hi,
Please give advice why I get error.

When I step into RunInvComment code, it first mark first line but
doesn't trigger "ShowComment". Then it mark second line and show error
"You can't execute code in break mode". Of cource I when I started to
step into this, it was_not_break_mode.

Sub RunInvComment()
Application.OnTime Now + TimeValue("00:00:00"), "ShowComment"
Application.OnTime Now + TimeValue("00:00:03"), "Deletecomment"
End Sub

Sub Deletecomment()
Selection.ClearComments
End Sub

Sub ShowComment()
Selection.AddComment "This is a 3 sec Comment !"
Selection.Comment.Visible = True
End Sub

Kind reagrds
tskogstrom


NickHK

OnTime code error "can't execute code in break mode"
 
As I understand it :

Your first .OnTime is basically Now, so you confuse the compiler as to what
it should be doing.
If you give yourself more time (an extra ~ 5 seconds), those lines will have
chance to execute in break mode, before it/they are due to fire.

One point ; you should check that selection is a single cell, otherwise your
routine will fail.
Also, you save the address of the inserted comment, so you can remove it if
the user changes the selection between those 2 calls.

NickHK

"tskogstrom" wrote in message
ups.com...
Hi,
Please give advice why I get error.

When I step into RunInvComment code, it first mark first line but
doesn't trigger "ShowComment". Then it mark second line and show error
"You can't execute code in break mode". Of cource I when I started to
step into this, it was_not_break_mode.

Sub RunInvComment()
Application.OnTime Now + TimeValue("00:00:00"), "ShowComment"
Application.OnTime Now + TimeValue("00:00:03"), "Deletecomment"
End Sub

Sub Deletecomment()
Selection.ClearComments
End Sub

Sub ShowComment()
Selection.AddComment "This is a 3 sec Comment !"
Selection.Comment.Visible = True
End Sub

Kind reagrds
tskogstrom





All times are GMT +1. The time now is 02:46 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com