Share via

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

Anonymous
2014-10-01T12:36:11+00:00

I have a tool for changing the font of the text and applying border to the text box in a presentation.

It works normally on text inserted in the text boxes. But when I insert a Table and then do these changes on the table without selecting the whole table, it gives me the following error - 


Run-time error '-2147024809 (80070057)'

The specified Value is out of range


I tried to debug this error but could not find anything. All I know is that it occurs at this line [Bold] - 


Dim v1 As TextRange2

For Each v1 In ActiveWindow.Selection.ShapeRange.TextFrame2.TextRange

If v1.Runs.Count >0 Then

For counter =1 Tov1.Runs.Count

v1.Runs(counter).Font.Fill.Solid

Next counter

End If

Next


Microsoft 365 and Office | PowerPoint | For home | Windows

Locked Question. This question was migrated from the Microsoft Support Community. You can vote on whether it's helpful, but you can't add comments or replies or follow the question.

0 comments No comments

Answer accepted by question author

Anonymous
2014-10-01T13:10:04+00:00

If you are selecting a Table, or just selecting the text in one cell of the table (or if you just select the text in the TextBox and not the TextBox itself), the Type of the Selection changes and you must deal with it slightly differently.  Try something like the code below.

Hope this helps,

Eric

Option Explicit

Sub testit()

    Dim i As Long

    Dim counter As Long

    Dim v1 As TextRange2

    Dim myTable As Table, myRow As Row, myCell As Cell

    Select Case ActiveWindow.Selection.Type

        Case ppSelectionShapes ' This is some kind of shape

            Select Case ActiveWindow.Selection.ShapeRange.Type

            Case msoTextBox ' The shape is a TextBox

                For Each v1 In ActiveWindow.Selection.ShapeRange.TextFrame2.TextRange

                    If v1.Runs.Count > 0 Then

                        For counter = 1 To v1.Runs.Count

                            v1.Runs(counter).Font.Fill.Solid

                            v1.Runs(counter).Font.Fill.ForeColor.RGB = RGB(255, 123, 25)

                        Next counter

                    End If

                Next

            Case msoTable ' The shape is a Table

                Set myTable = ActiveWindow.Selection.ShapeRange.Table

                For Each myRow In myTable.Rows

                    For Each myCell In myRow.Cells

                        For Each v1 In myCell.Shape.TextFrame2.TextRange

                            If v1.Runs.Count > 0 Then

                                For counter = 1 To v1.Runs.Count

                                    v1.Runs(counter).Font.Fill.Solid

                                    v1.Runs(counter).Font.Fill.ForeColor.RGB = RGB(255, 123, 25)

                                Next counter

                            End If

                        Next

                    Next myCell

                Next myRow

            Case Else

            End Select

        Case ppSelectionText ' This is just selected text (in some shape)

            Set v1 = ActiveWindow.Selection.TextRange2

            If v1.Runs.Count > 0 Then

                For counter = 1 To v1.Runs.Count

                    v1.Runs(counter).Font.Fill.Solid

                    v1.Runs(counter).Font.Fill.ForeColor.RGB = RGB(255, 123, 25)

                Next counter

            End If

        Case Else

    End Select

End Sub

Was this answer helpful?

2 people found this answer helpful.
0 comments No comments

1 additional answer

Sort by: Most helpful
  1. Anonymous
    2014-10-02T20:58:06+00:00

    Hey !!

    Thanks a ton man, that worked well. But I have another thing that is not working.

    I have a piece of code to assign color to the border of the textbox. But when I do that for table it gives me the same error.

    Private m_lngCurrentSelectedColor As Long

    Private Property Get CurrentSelectedColor() As Long

    CurrentSelectedColor = m_lngCurrentSelectedColor

    End Property

    Private Sub SetPaintColor()

    If CurrentSelectedColor = NoCurrentColor Then Exit Sub

    With ActiveWindow.Selection.ShapeRange.Line

    .ForeColor.RGB = CurrentSelectedColor

    .Visible = msoTrue

    .Transparency = 0

    End With

    End Sub

    Was this answer helpful?

    0 comments No comments