Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I have a start stop time button excel 2010 sheet to keep track of how much I spend on tasks at work. It was working fine until this morning and I am getting a Run-time Error 424 Message. The code is below. Any help you can give will be greatly appreciated!!

Option Explicit

Private Sub btnStart_Click()
ActiveSheet.Unprotect
    Cells(Rows.Count, 5).End(xlUp).Offset(1) = Date
    Cells(Rows.Count, 6).End(xlUp).Offset(1) = Now
    Cells(Rows.Count, 7).End(xlUp).NumberFormat = "hh:mm"
    Cells(Rows.Count, 8).End(xlUp).Offset(1) = Environ("username")
    Me.btnStart.Enabled = False
    Me.btnStop.Enabled = True

End Sub

Private Sub btnStop_Click()
ActiveSheet.Unprotect
    Cells(Rows.Count, 7).End(xlUp).Offset(1) = Now
    Cells(Rows.Count, 7).End(xlUp).NumberFormat = "hh:mm"
    Me.btnStart.Enabled = True
    Me.btnStop.Enabled = False
End Sub

Private Sub Worksheet_SelectionChange(ByVal Target As Range)

End Sub

Public RunWhen As Double
Public Const cRunIntervalSeconds = 10 ' 10 seconds
Public Const cRunWhat = "The_Sub"  ' the name of the procedure to run


Sub StartTimer()
    RunWhen = Now + TimeSerial(0, 0, cRunIntervalSeconds)
    Application.OnTime EarliestTime:=RunWhen, Procedure:=cRunWhat, Schedule:=True
End Sub
Sub The_Sub()
 [a1] = Now
   ' Call StartTimer to schedule the procedure again
   StartTimer
End Sub
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
218 views
Welcome To Ask or Share your Answers For Others

1 Answer

As noted in the comments to your question, since your button is a Form button, I suspect that the macro that is assigned to it is not correct or not able to be accessed. If you are trying to run btnStart_Click() from your Form control, you will need to remove the Private designation from the Private Sub btnStart_Click() line. The same goes for the btnStop_Click() sub.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...