You are getting the "Argument not optional" message because the
StartBlink
sub-routine expects a parameter to be passed to it and you have not included the
BlinkCell
in the call to
OnTime
Normally, to pass a parameter using
OnTime
you would enclose the sub name and parameter list within single-quotes, such as
Application.OnTime RunWhen, "'StartBlink H,10'", , True
but that is not an easy thing when the parameter is a
Range
. You could pass in the cell name and construct the range within the
StartBlink
sub, but I found it easier just to pull the range out to a public variable
Public BlinkCell As Range
so the routine signature becomes
Sub StartBlink()
That now works.
Gary Heath wrote:
I am not sure what this RunWhen stuff does
Chip Pearson wrote the original code and in this
article[
^] he explains why RunWhen is abstracted out to a public variable - see the section on stopping the timer.
Gary Heath wrote:
if I debug I get the message "Can't execute code in break mode" !!
That message is generated from the pending OnTime call. Basically it is saying that it can't execute the call because you have the program stopped in the debugger and it is trying to run it every second. If you temporarily change the interval e.g.
RunWhen = Now + TimeSerial(0, 0, 15)
you will get an opportunity (well, a 15 second opportunity!) to debug. Alternatively you can call the
StopBlink
routine from the Immediate window to cancel any pending timers.