Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/vba/17.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在VBA中创建计数计时器_Vba_Powerpoint - Fatal编程技术网

如何在VBA中创建计数计时器

如何在VBA中创建计数计时器,vba,powerpoint,Vba,Powerpoint,我试图在Powerpoint演示文稿的VBA中创建每秒递增1的计数器。这就是我到目前为止提出的问题 Sub countup() Dim index As Integer index = 0 Do Until index > 100 index = index + 1 DoEvents With ActivePresentation.Slides(1).Shapes(3).TextFrame.TextRange .T

我试图在Powerpoint演示文稿的VBA中创建每秒递增1的计数器。这就是我到目前为止提出的问题

Sub countup()
    Dim index As Integer

    index = 0
    Do Until index > 100
    index = index + 1

    DoEvents
        With ActivePresentation.Slides(1).Shapes(3).TextFrame.TextRange
        .Text = index
        End With

    Loop
End Sub

此代码在101之前递增1,但不会每秒递增1。这是在VBA Powerpoint中,因此我无法放置计时器控件。希望你能帮忙。谢谢。

这是一个可能的解决方案:

Public Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)

Public Sub TestMe2()

    Dim index As Long
    index = 0

    Do Until index > 10
        index = index + 1
        Debug.Print index
        Sleep (1000)
    Loop

End Sub
如果不添加
.Net
功能,可以这样做:

Public Sub TestMe()

    Dim lngIndex            As Long
    Dim sngSec              As Single '9GAG
    Dim sngAddSec           As Single

    sngAddSec = 1

    Do Until lngIndex > 4
        lngIndex = lngIndex + 1
        sngSec = Timer + sngAddSec
        Debug.Print lngIndex
        While Timer < sngSec: Wend
    Loop

End Sub
公共子TestMe()
暗指数和长指数一样
尺寸sngSec为单个'9GAG
Dim sngAddSec作为单个
sngAddSec=1
直到lngIndex>4为止
lngIndex=lngIndex+1
sngSec=计时器+sngAddSec
调试。打印索引
当计时器