运行时错误424对象必需 - VBA启动停止 [英] Run Time Error 424 Object Required- VBA Start Stop
问题描述
我有一个开始停止时间按钮excel 2010表,以跟踪我花在工作上的工作量。这是正常工作,直到今天上午,我得到一个运行时错误424消息。代码如下。任何你可以给予的帮助将非常感谢!
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
推荐答案
如您对问题的评论所述,由于您的按钮是表单按钮,我怀疑分配给它的宏不正确或无法访问。如果您尝试从表单控件中运行 btnStart_Click()
,则需要从code私人中删除 Private Sub btnStart_Click()
行。对于 btnStop_Click()
sub。
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.
这篇关于运行时错误424对象必需 - VBA启动停止的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!