npatterson27
npatterson27

Reputation: 11

Selecting and deleting textboxs with specific text string in powerpoint

I am trying to select a textbox in powerpoint with a specific word and delete it. The text box appears on each slide in the presentation, and I would like to delete each text box on each slide in the presentation. The textboxes with the word I am trying to delete has the word "Page" in it.

I have tried using some other code I seen in the internet but nothing happens to the presentation when I run the code. Wondering what I am missing for the textbox to be deleted?

I have some code I tried already:

Sub deletor()
    On Error Resume Next
    Dim osld As Slide
    Dim L As Long
    For Each osld In ActivePresentation.Slides
        For L = osld.Shapes.Count To 1 Step -1
            If osld.Shapes(L).HasTextFrame Then
                If osld.Shapes(L).TextFrame.HasText Then
                    ' obviously use their address
                    If LCase(osld.Shapes(L).TextFrame.TextRange) Like LCase("Page") Then
                        osld.Shapes(L).Delete
                    End If
                End If
            End If
        Next
    Next
End Sub

No error messages, just no actions in excel (the textboxes with the word page are still there). This makes me assume the macro is running but is not doing what I am trying to code it to do.

Upvotes: 1

Views: 1230

Answers (1)

Sam
Sam

Reputation: 5721

The problem is in the line

If LCase(osld.Shapes(L).TextFrame.TextRange) Like LCase("Page") Then

The Like operator uses a wildcard pattern. I would guess that the pattern you want is

... Like "page*"

or

... Like "*page*"

No need to LCase a string you are writing as a literal value.

Upvotes: 1

Related Questions