我想在powerpoint中创建一个宏,当我点击按钮时,该值增加1,我有以下宏,在延迟秒之间递增计数器,但我想在点击时增加计数器,如何我能改变吗?
Private Sub CommandButton1_Click()
Offset = ActivePresentation.PageSetup.SlideHeight + 10
CountNo = 1
' ADJUST THIS waitTime NUMBER WITH SECONDS DELAY BETWEEN COUNTER INCREMENTS
waitTime = 0.5
' ADJUST THIS maxCount NUMBER WITH MAXIMUM NUMBER COUNTER SHOULD REACH
maxCount = 5000
Do Until CountNo = maxCount + 1
ActivePresentation.SlideMaster.Shapes("Counter").TextFrame.TextRange.Text = CountNo
ActivePresentation.SlideMaster.Shapes("Counter").Top = ActivePresentation.SlideMaster.Shapes("Counter").Top + Offset
DoEvents
ActivePresentation.SlideMaster.Shapes("Counter").Top = ActivePresentation.SlideMaster.Shapes("Counter").Top - Offset
x = Timer
While Timer - x < waitTime
DoEvents
Wend
CountNo = CountNo + 1
If SlideShowWindows.Count = 0 Then
ActivePresentation.SlideMaster.Shapes("Counter").TextFrame.TextRange.Text = 1
ActivePresentation.SlideMaster.Shapes("Counter").Top = ActivePresentation.SlideMaster.Shapes("Counter").Top + Offset
DoEvents
ActivePresentation.SlideMaster.Shapes("Counter").Top = ActivePresentation.SlideMaster.Shapes("Counter").Top - Offset
Exit Do
End If
Loop
End Sub
答案 0 :(得分:0)
我认为你提出了错误的问题,但是举个例子:
这会从形状中读取CountNo
,将计数器增加1,并在每次单击该按钮时将其写回形状。
Private Sub CommandButton1_Click()
Dim CountNo As Long
CountNo = ActivePresentation.SlideMaster.Shapes("Counter").TextFrame.TextRange.Text
'read the count no from the shape counter
CountNo = CountNo + 1 'increase the count no by 1
ActivePresentation.SlideMaster.Shapes("Counter").TextFrame.TextRange.Text = CountNo
'write the count no back to the shape counter
End Sub
此代码预计在ActivePresentation.SlideMaster
中有一个形状.Shapes("Counter")
,其.TextFrame.TextRange.Text
中包含一个数字。