运行时错误 424 需要对象 - VBA 开始停止

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/27607971/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-12 05:37:02  来源:igfitidea点击:

Run Time Error 424 Object Required- VBA Start Stop

excelvbaruntimeruntime-error

提问by Laura Walker

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!!

我有一个开始停止时间按钮 excel 2010 表来跟踪我在工作任务上花费了多少。直到今天早上它都运行良好,我收到了运行时错误 424 消息。代码如下。您能提供的任何帮助将不胜感激!!

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

回答by TheEngineer

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 Privatedesignation from the Private Sub btnStart_Click()line. The same goes for the btnStop_Click()sub.

正如对您的问题的评论所述,由于您的按钮是一个表单按钮,我怀疑分配给它的宏不正确或无法访问。如果您尝试btnStart_Click()从 Form 控件运行,则需要PrivatePrivate Sub btnStart_Click()行中删除指定。btnStop_Click()子节点也是如此。

回答by Sara

Good afternoon, I had a similar issue with a form control in an Excel spreadsheet that was working just fine one day, and the next day, it could no longer "find" the form control and displayed the same error.

下午好,我遇到了一个与 Excel 电子表格中的表单控件类似的问题,该问题一天工作正常,第二天,它无法再“找到”表单控件并显示相同的错误。

After doing a Google search within the past 24 hours I located a post that points the finger at December security updates.

在过去 24 小时内进行 Google 搜索后,我找到了一个帖子,指出 12 月的安全更新。

http://blogs.technet.com/b/the_microsoft_excel_support_team_blog/archive/2014/12/11/forms-controls-stop-working-after-december-2014-updates-.aspx

http://blogs.technet.com/b/the_microsoft_excel_support_team_blog/archive/2014/12/11/forms-controls-stop-working-after-december-2014-updates-.aspx

I know this isn't very helpful but it's something.

我知道这不是很有帮助,但它是有用的。

Edit/Update: Worked with my PC Tech guru and he was able to resolve the issue by re-registering two DLL's and deleting .EXD files in the user profile. The .EXD files get recreated (and thusly recompiled) the next time Excel opens.

编辑/更新:与我的 PC 技术专家一起工作,他能够通过重新注册两个 DLL 并删除用户配置文件中的 .EXD 文件来解决该问题。.EXD 文件在下次打开 Excel 时重新创建(并因此重新编译)。

Here are the DLL's:

这是DLL的:

c:\windows\syswow64\COMCTL32.OCX

c:\windows\syswow64\COMCTL32.OCX

c:\windows\syswow64\MSCOMCTL.OCX

c:\windows\syswow64\MSCOMCTL.OCX

Good luck!

祝你好运!