1

I am trying to check for red fonts in a powerpoint slide. I want to store the slide number that contain the red font in the array and display in a single dialog box. Currently it displays one slide number in one dialog box.

My current code looks like the following. Can anybody tell how can I store it an array and display it?

Private Sub CommandButton1_Click()

    Dim sld As Slide
    Dim shp As Shape
    Dim x As Byte

    With ActivePresentation
        z = .Slides(.Slides.Count).SlideNumber
        MsgBox z, vbDefaultButton1, "Total Slides"
    End With

    Dim myarray() As Integer
    ReDim myarray(0 To 2)

    For i = 2 To z
        Set sld = ActivePresentation.Slides(i)

        For Each shp In sld.Shapes
            If shp.TextFrame.TextRange.Font.Color.RGB = RGB(255, 0, 0) Then
                MsgBox i, vbDefaultButton2, "Slide with RED font"
            End If
        Next shp
    Next

End Sub

1 Answer 1

1

Instead of an array I'd use a collection like that

Private Sub CommandButton1_Click()

Dim sld As Slide
Dim shp As Shape
Dim x As Byte
Dim z, i

    With ActivePresentation
        z = .Slides(.Slides.Count).SlideNumber
        MsgBox z, vbDefaultButton1, "Total Slides"
    End With

    Dim myCol As Collection
    Set myCol = New Collection


    For i = 2 To z
        Set sld = ActivePresentation.Slides(i)
        For Each shp In sld.Shapes
            If shp.TextFrame.TextRange.Font.Color.RGB = RGB(255, 0, 0) Then
                ' MsgBox i, vbDefaultButton2, "Slide with RED font"
                myCol.Add CStr(i), CStr(i)
            End If
        Next shp
    Next

    Dim j As Long
    For j = 1 To myCol.Count
        Debug.Print myCol.Item(j)
    Next j


End Sub
Sign up to request clarification or add additional context in comments.

1 Comment

Thats perfect. A bit different but does the same thing. Bingo

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.