我正在使用以下vba代码将宏延迟半秒,但由于某种原因,这行代码不能使用不到一秒的任何代码。有人可以告诉我我哪里出错了?感谢
这条线是问题,它不会让我放入不到一秒的任何东西。我需要这个半秒钟。
Application.OnTime Now + TimeValue("00:00:01"), "DoMarquee"
Sub DoMarquee()
Dim sMarquee As String
Dim iWidth As Integer
Dim iPosition As Integer
Dim rCell As Range
Dim iCurPos As Integer
'Set the message to be displayed in this cell
sMarquee = "This is a scrolling Marquee."
'Set the cell width (how many characters you want displayed at once
iWidth = 10
'Which cell are we doing this in?
Set rCell = Sheet1.Range("M2")
'determine where we are now with the message.
' instr will return the position of the first
' character where the current cell value is in
' the marquee message
iCurPos = InStr(1, sMarquee, rCell.Value)
'If we are position 0, then there is no message, so start over
' otherwise, bump the message to the next characterusing mid
If iCurPos = 0 Then
'Start it over
rCell.Value = Mid(sMarquee, 1, iWidth)
Else
'bump it
rCell.Value = Mid(sMarquee, iCurPos + 1, iWidth)
End If
'Set excel up to run this thing again in a second or two or whatever
Application.OnTime Now + TimeValue("00:00:01"), "DoMarquee"
End Sub
答案 0 :(得分:0)
您不能使用该机制少于一秒钟的触发。还有另一种选择。请参阅:Excel VBA OnTime for less than 1 second without becoming Unresponsive