返回表示自午夜以来已过的秒数的 Single 。

语法

Timer

备注

在 Windows 中, 计时器 函数返回秒的小数部分。 在 Macintosh 中,定时器分辨率为 1 秒。

示例

此示例使用 Timer 函数来暂停应用程序。 该示例还使用 DoEvents 在暂停期间向其他进程屈服。

Dim PauseTime, Start, Finish, TotalTime

If (MsgBox("Press Yes to pause for 5 seconds", 4)) = vbYes Then

PauseTime = 5 ' Set duration.

Start = Timer ' Set start time.

Do While Timer < Start + PauseTime

DoEvents ' Yield to other processes.

Loop

Finish = Timer ' Set end time.

TotalTime = Finish - Start ' Calculate total time.

MsgBox "Paused for " & TotalTime & " seconds"

Else

End

End If

另请参阅

函数 (Visual Basic for Applications)

支持和反馈

有关于 Office VBA 或本文档的疑问或反馈? 请参阅 Office VBA 支持和反馈,获取有关如何接收支持和提供反馈的指南。