PowerPoint Clipboard Flakiness RRS feed

  • Question

  • In PowerPoint 2019, I get random errors of "Run-time error '-2147221040 (800401d0)': Method 'Cut' of object 'TextRange2' failed" when running this code:

      For Each objSlide In ActivePresentation.Slides
        objSlide.CustomLayout = objSlide.CustomLayout
        Select Case objSlide.CustomLayout.Name
          Case "Text Page", "Text Page No Bullets", "Text Page - Two Columns", "Title Only", "Title and Content", _
          "Title and Content - 2 Columns", "Title and Content - 2 Rows", "Title and Content - Quadrant", "Full Page Content"
            'Move subtitles to Title placeholders
            For Each objShape In objSlide.Shapes
              If objShape.Type = msoPlaceholder Then
                If objShape.PlaceholderFormat.Type = ppPlaceholderBody And objShape.Top > 25 And objShape.Top < 72 _
                And objShape.HasTextFrame And objShape.TextFrame2.HasText Then
                  With objSlide.Shapes.Placeholders(1).TextFrame2.TextRange
                    .InsertAfter vbCr
                    .InsertAfter(vbCr).PasteSpecial msoClipboardFormatPlainText
                  End With
                End If
              End If
            Next objShape
          Case Else
            'No Action
        End Select
    It will trip over any of the layouts, or it will just run as intended, there's no rhyme or reason. I assume it's the clipboard being flakey. Any ideas how to work around this?

    Monday, April 29, 2019 9:07 PM

All replies

  • A short nap was needed. I added to my declarations:

    Private Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)

    Then just before the Cut command, I added:

    Sleep 20

    Problem solved!

    Thursday, May 9, 2019 2:11 PM