Create Timer in Excel (Wait, Sleep, DoEvents Functions)
Автор: Ah Sing TV
Загружено: 2018-04-21
Просмотров: 8389
Описание:
How to create a timer in Excel using "Application.Wait", "Sleep" or "DoEvents" function?
How to create a stopwatch in Excel? at • Create Stopwatch in Excel
----------------------------------------------------------------------------------------------------------
VBA Code with "Wait" function:
Sheet1.Shapes.Range(Array("TextBox 1")).TextFrame2.TextRange.Characters.Text = 10
Sheet1.Shapes.Range(Array("Pie 2")).Adjustments.Item(1) = 0
For i = 1 To 10
Application.Wait (Now + #12:00:01 AM#)
Sheet1.Shapes.Range(Array("TextBox 1")).TextFrame2.TextRange.Characters.Text = 10 - i
Sheet1.Shapes.Range(Array("Pie 2")).Adjustments.Item(1) = i / 10 * 359.9
Next i
Application.Wait (Now + #12:00:01 AM#)
Sheet1.Shapes.Range(Array("TextBox 1")).TextFrame2.TextRange.Characters.Text = 0
Sheet1.Shapes.Range(Array("Pie 2")).Adjustments.Item(1) = 359.9
MsgBox ("Time Out!")
*Remark: #hh:mm:ss#
-----------------------------------------------------------------------------------------------------------
The minimum delay that the "Wait" function can make is 1 second. If want milliseconds, then "Sleep" function is a good choice. To use the "Sleep" function, declare the following:
#If VBA7 Then
Declare PtrSafe Sub Sleep Lib "kernel32" (ByVal Milliseconds As LongPtr)
#Else
Declare Sub Sleep Lib "kernel32" (ByVal Milliseconds As Long)
#End If
*Remark: The declaration must be made on a module or else Excel will show:
"Compile error:
Constants, fixed-length strings, arrays, user-defined types and Declare statements not allowed as Public members of object modules."
Повторяем попытку...
Доступные форматы для скачивания:
Скачать видео
-
Информация по загрузке: