【问题标题】:Pass a new value on mouse click在鼠标点击时传递一个新值
【发布时间】:2020-10-01 08:12:25
【问题描述】:

我在 Slide1 上有一个名为“问题”的形状,在 Slide2 上有一个包含 8 个问题的 8x1 表格。 我编写了一个程序,当单击形状时将问题传递给形状的文本范围:

Sub Questions()
    Dim qRange As TextRange, qTable As Table
    Set qRange = ActivePresentation.Slides(1).Shapes("Question").TextFrame.TextRange
    Set qTable = ActivePresentation.Slides(2).Shapes(1).Table
    For i = 1 To 8
        qRange = qTable.Cell(i, 1).Shape.TextFrame.TextRange
    Next
End Sub

但是,该形状会立即显示最后一个问题,而不是在鼠标单击时一一显示。如何捕获鼠标单击事件以在 PowerPoint 中显示每个问题?

【问题讨论】:

  • 一种选择可能是使用 Static 变量而不是循环,并在宏内部将其递增 1,添加一些逻辑以将其重置为 0(如果之前等于 8)递增。未经测试,但我认为应该可以。
  • 你的意思是:while i
  • 不,你不会使用循环。

标签: vba powerpoint


【解决方案1】:

一种选择可能是使用 Static 变量而不是循环,并在宏内将其递增 1,如果在递增之前等于 8,则添加一些逻辑将其重置为 0。

Sub Questions()
    Dim qRange As TextRange, qTable As Table
    Set qRange = ActivePresentation.Slides(1).Shapes(1).TextFrame.TextRange
    Set qTable = ActivePresentation.Slides(2).Shapes(1).Table
    
    Static i As Long
    If i = 8 Then
        i = 0 'Reset to loop again from the beginning
    End If
    
    i = i + 1
    qRange = qTable.Cell(i, 1).Shape.TextFrame.TextRange
End Sub

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-06-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多