Nicolas Bulgarides
Nicolas Bulgarides

Reputation: 27

For Each Loop - Text from color X to Y

I'm making a rudimentary game in PPT using VBA for work. One of the components is a personality test with multiple choice questions. The way I have decided to do this is to have the four answers as separate text boxes, default color of black. When any text block is clicked, it will change the text in that textblock to red, and turn all other text blocks to black, so that only 1 text block is ever red at a time. A button at the bottom will determine which textbox has red text, and based off that save a variable in an array that will go into calculating the personality type.

Right now, I'd like a loop statement that runs through a single slide to evaluate the text. Later on i'll modify it to accept a passed-in slide number (So I can use the function on every slide with questions). I'm not even worried about the if statement to decide when to swap color, I can't even get the loop to simply change ALL text (which should be so simple...)

As I see it, the loop needs to: 1) Check every object in a single pre-determined slide to see if it has text 2) Change the color of all text to a color entered in the code.

''' Sub fontChangeWhy()

Dim oSl As Slide
Dim oSh As Shape


oSl = ActivePresentation.Slides(2)

    For Each oSh In oSl.Shapes
        If oSh.HasTextFrame Then
            If oSh.TextFrame.HasText Then
                oSh.TextFrame.TextRange.Font.Color.RGB = RGB(0, 0, 0)
            End If
        End If
    Next oSh

End Sub '''

Upvotes: 0

Views: 49

Answers (1)

Legxis
Legxis

Reputation: 916

oSl is an object, so it needs to be set

Set oSl = ActivePresentation.Slides(2)

Upvotes: 1

Related Questions