rainie28
rainie28

Reputation: 33

Pass a new value on mouse click

I have a shape named "Question" on Slide1 and a 8x1 table containing 8 questions on Slide2. I wrote a procedure which passes a question to the shape's text range when the shape is clicked:

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

However, the shape displayed the last question right away, not one-by-one on mouse click. How can I capture a mouse click event to show each question in PowerPoint?

Upvotes: 0

Views: 52

Answers (1)

BigBen
BigBen

Reputation: 49998

One option might be to use a Static variable instead of looping, and increment it by one inside the macro, adding some logic to reset it to 0 if it's equal to 8 before incrementing.

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

Upvotes: 1

Related Questions