Setting a maximum number for a label in PowerPoint-VBA

时间:2018-02-03 10:27:16

标签: vba powerpoint-vba

Sub PlusOne()
counter.Caption = (counter.Caption) + 1
End Sub
Sub MinusOne()
counter.Caption = (counter.Caption) - 1
End Sub

Above is the Visual Basic Code which I use for a PowerPoint Scoreboard (to increase +1 or -1 in the label).

How do I add a maximum number which can be increased in the label. If I press the shape containing Sub PlusOne the label will increase indefinitely.

How do I set a maximum number which a label can display.. let us take 150.

Basically, I want the number of the label to increase upto 150 only.

1 个答案:

答案 0 :(得分:0)

如果我使用Microsoft Forms 2标签,以下内容适用于我。

我在公共变量中保存标签的当前值。另外,我为最大数字添加了一个公共常量,以便于调整。

我使用here中的语法来确定如何设置多次运行test子的测试构造,即使用Application.Run的文件名和子名称循环。

Option Explicit 
Public currVal As Long
Public Const maxValue As Long = 150

Public Sub RunTest

    Dim i As Long
    currVal = 0

    Do While i < 152 'change to test

        Application.Run "'Presentation1.pptm'!test" ' where it is name of presentation and name of sub

    Loop

    Msgbox currVal

End Sub

Public Sub test()

    Dim myLabel As Label

    Set myLabel = ActivePresentation.Slides(1).Shapes("Label1").OLEFormat.Object

    If currVal < maxValue Then CurrVal = CurrVal + 1

    myLabel.Caption = currVal

End Sub