问题
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
回答1:
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.
回答2:
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.
After doing a Google search within the past 24 hours I located a post that points the finger at December security updates.
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.
Here are the DLL's:
c:\windows\syswow64\COMCTL32.OCX
c:\windows\syswow64\MSCOMCTL.OCX
Good luck!
来源:https://stackoverflow.com/questions/27607971/run-time-error-424-object-required-vba-start-stop