【问题标题】:Counter Macro VBA Powerpoint计数器宏 VBA Powerpoint
【发布时间】:2018-01-30 14:28:44
【问题描述】:

我想在 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

【问题讨论】:

    标签: vba counter increment powerpoint


    【解决方案1】:

    我认为你问错了问题,但给你举个例子:

    这会从形状中读取CountNo,将计数器加一,然后在您每次单击该按钮时将其写回形状。

    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 中包含一个数字。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-10-11
      • 2022-01-12
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-03-08
      • 2018-10-07
      • 1970-01-01
      相关资源
      最近更新 更多