vba - The specified value is out of range



I am trying to display slide no. in immediate window if they even one text box with a red font word. But the following error keeps popping up. Any ideas how I can go ahead.

Run-time error'-2147024809(80070057) The specified value is out of range.


Sub redfont()

    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 x = 1 Then
            x = 1
            ElseIf shp.TextFrame.TextRange.Font.Color.RGB = RGB(255, 0, 0) Then
                myCol.Add CStr(i), CStr(i)
                x = 1
            End If
        Next shp
        x = 0

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

End Sub

1 Answer: 

not all shapes have a TextFrame, so check it out before trying access to it

For i = 2 To z
    Set sld = ActivePresentation.Slides(i)
    For Each shp In sld.Shapes
        If shp.HasTextFrame Then
            If shp.TextFrame.TextRange.Font.Color.RGB = RGB(255, 0, 0) Then
                myCol.Add CStr(i), CStr(i)
                Exit For
            End If
        End If

BTW: you don't need that x and just exit loop when first condition is met


More Articles

Using Android Presentation class with a Bluetooth mouse

I am attempting to use the Presentation class for Android to display a secondary app on another display which can be navigated with the mouse; however, when I connect a Bluetooth mouse to the phone it only shows the cursor and allows for click inputs on the phone's primary display. Is there a way to

r - Include googleVis chart in ioslides RStudio

I have a following chart:library(googleVis)df = data.frame(models = c("PLAT", "LC", "APC", "CBD", "M6", "M7", "M8"), val = 1:7)Column <- gvisColumnChart(df)plot(Column)I would like to place it in ioslides in RStudio.Can anyone instruct me how to do it?

android - runOnUiThread in Presentation class

How can I update TextView in Presentation class if RunOnUiThread is not available in this class.Here is my exampleprivate final class DemoPresentation extends Presentation { public DemoPresentation(Context context, Display display) { super(context, display); } @Override protected

css - Presenting two paragraphs in HTML side by side

Consider the following problem: you have one text translated into two languages,First line // Unua linioSecond line // Dua linioand there's a need to display them side by side using all available space, make them accessible to search engines as separate paragraphs and allowing separate selection. Th

r - Control size of figure in Rstudio presentation

I'm creating a presentation in RStudio (.Rpres). I have a figure that is too large and extends beyond the screen. How can I reduce it?Too big, need to reduce sizeFigure 1========================================================![alt text](fig1)

html - Vertical and Horizontal alignment

I am designing an html page where I need to display my inserted images. I want the arrangement of images in such a way :Image1 Image2 Image3 Image4 Image5 Image6 Image7 Image8 Image9<html> <head> <title>Display Images</title> </head> <body> {% for image in

objective c - iOS Now Playing View Similar To Music/Spotify App

I am trying to figure out how to create a "Now Playing" view similar to the one in the Music app and the Spotify app.Here are a few images of what I'm trying to re-create:Creating the view is not the problem. The part I'm having trouble with is how to keep the view on the screen at the bottom with t

html - Reveal.js iframe background

I want an embedded iframe to be full screen (or an adjusted percentage of the full screen) in a reveal.js presentation. This discussion implies that I can set the iframe as a background, but this returns the default background:<section data-background="http://viz.healthmetricsandevaluation.org/f

jquery - Chaining animated sequences for an infinite loop presentation

I'm coding up a presentation for display on a TV in the office reception area and need some help please.I've tried numerous StackOverflow answers to try and resolve this, but none relate particularly well to my situation. I have spent days trying to solve this and am ready to quit.Here's the main bu

apache poi - What are these fonts in a powerpoint pptx file?

I want to collect font information of a pptx with the help of Apache POI. I basically search for string typeface= in the xmlObject of a powerpoint slide.In some of my files, I can see a bunch of lines that contains the search string: <a:latin typeface="+mn-lt"/> <a