在Excel中创建秒表,在操作工作表时运行

时间:2018-03-29 20:27:04

标签: excel vba excel-vba

我试图在单元格K1中使用“开始”和“停止”按钮在Excel中创建一个秒表,即使其他单元格在工作表上更新也会继续运行。

我在工作表的VBA窗口中尝试使用以下代码,但我收到一条错误消息,说“&34;无法运行宏'更新时间'”。宏可能在此工作簿中不可用,或者可能禁用所有宏。"我很肯定宏已启用,文件保存为.xlsm。我应该如何更新代码才能使其正常工作?

Sub UpdateTime()

Range("K1").Value = Now - gdtStart
DoEvents

If Not gbStop Then
    Application.OnTime Now + TimeSerial(0, 0, 1), "UpdateTime"
End If
End Sub

Private Sub CommandButton1_Click()
    Range("K1") = Format(0, "00") & ":" & Format(0, "00") & ":" & Format(0, 
    "00")
    gbStop = False
    gdtStart = Now
    Application.OnTime Now + TimeSerial(0, 0, 1), "UpdateTime"

End Sub

Private Sub CommandButton2_Click()

    gbStop = True

End Sub

可用模块/表格的屏幕截图

screenshot of the modules/sheets available

0 个答案:

没有答案
相关问题