【发布时间】:2016-05-11 20:49:21
【问题描述】:
我正在使用 Excel 2010,并想在 Excel 中创建一个倒数计时器。代码将通过使用带有宏的按钮来启动和停止。按下“开始”按钮时会出现问题。上面的代码使用 Cell "B1" 作为输入点,因为我只是想让它工作,但每次我尝试时,它总是说: “无法运行宏。此工作簿中可能没有该宏,或者所有宏都可能被禁用”。
是的,我在把它放在这里之前启用了所有宏。我希望能够接受用户输入,并使其成为计时器开始的时间,而不仅仅是使用单元格“B1”。
'Macro for Starting the timer (attached to the start button)
Sub startTimer()
Application.OnTime Now + TimeValue("00:00:01"), "nextTick"
End Sub
'Macro for next second
Sub nextTick()
Sheet1.Range("B1").Value = Sheet1.Range("B1").Value - TimeValue("00:00:01")
startTimer
End Sub
'Macro for stopping the timer (attached to the end button)
Sub stopTimer()
Application.OnTime Now - TimeValue("00:00:01"), "nextTick", , False
End Sub
【问题讨论】:
-
此代码是在 module 代码表还是 sheet 代码表中?您是否通过右键单击工作表的名称选项卡并选择查看代码到达那里?您是否使用 [alt]+F11 打开 VBE 并使用下拉菜单插入 ► 模块?
-
@Jeeped 在主页面中