Consulting

Results 1 to 8 of 8

Thread: Deleting a specific text box

  1. #1
    VBAX Newbie
    Joined
    Oct 2013
    Posts
    1
    Location

    Deleting a specific text box

    Hello forum,

    I'm in urgent need of some assistance. I have this powerpoint presentation that occasionally has a text box in the top right corner with the text "TESTING - (slidenumber)". Unfortunately I did not make the presentation so I don't know where it came from, and it is quite long in many different parts.

    I tried searching around for a macro on the net but I got an error.

    Please help.

  2. #2
    VBAX Master
    Joined
    Feb 2007
    Posts
    2,093
    Location
    Probably need more detail but you could try this (ON A COPY)

    Sub killTEXT()
    Dim L As Long
    Dim osld As Slide
    For Each osld In ActivePresentation.Slides
    For L = osld.Shapes.Count To 1 Step -1
    With osld.Shapes(L)
    If .HasTextFrame Then
    If .TextFrame.TextRange Like "TESTING*" Then .Delete
    End If
    End With
    Next L
    Next osld
    End Sub
    John Wilson
    Microsoft PowerPoint MVP
    Amazing Free PowerPoint Tutorials
    http://www.pptalchemy.co.uk/powerpoi...tutorials.html

  3. #3
    VBAX Newbie
    Joined
    Sep 2017
    Posts
    4
    Location
    John - Thanks kindly for posting this. VERY new to the forum and VBA. VERY helpful code here!

    Definitely a newb question:

    How could I adapt this to also delete textboxes that contain a superscript character?

  4. #4
    VBAX Master
    Joined
    Feb 2007
    Posts
    2,093
    Location
    Try this:

    Be aware it will delete any shape with superscript text so be careful

    Sub killSS()
        Dim L As Long
        Dim R As Long
        Dim osld As Slide
        For Each osld In ActivePresentation.Slides
            For L = osld.Shapes.Count To 1 Step -1
                With osld.Shapes(L)
                    If .HasTextFrame Then
                        If .TextFrame.HasText Then
                        For R = 1 To .TextFrame.TextRange.Runs.Count
                        If .TextFrame.TextRange.Runs(R).Font.Superscript = True Then
                        osld.Shapes(L).Delete
                        End If
                        Next
                        End If
                    End If
                End With
            Next L
        Next osld
    End Sub
    John Wilson
    Microsoft PowerPoint MVP
    Amazing Free PowerPoint Tutorials
    http://www.pptalchemy.co.uk/powerpoi...tutorials.html

  5. #5
    VBAX Newbie
    Joined
    Sep 2017
    Posts
    4
    Location
    Getting a debug warning on the following line:

    If .TextFrame.TextRange.Runs(R).Font.Superscript = True Then

    Yes, trying this on a "historical" presentation for sure. I did try a couple of adjustments to this to no avail. I'm on PowerPoint 2013. (Sorry I didn't mention that earlier..)

  6. #6
    VBAX Master
    Joined
    Feb 2007
    Posts
    2,093
    Location
    Sorry I didn't check it!

    It should maybe be

    Sub killSS()    Dim L As Long
        Dim R As Long
        Dim osld As Slide
        For Each osld In ActivePresentation.Slides
            For L = osld.Shapes.Count To 1 Step -1
                With osld.Shapes(L)
                    If .HasTextFrame Then
                        If .TextFrame.HasText Then
                            For R = .TextFrame.TextRange.Runs.Count To 1 Step -1
                                If .TextFrame.TextRange.Runs(R).Font.Superscript = True Then
                                     .Delete
                                    Exit For
                                End If
                            Next
                        End If
                    End If
                End With
            Next L
        Next osld
    End Sub
    John Wilson
    Microsoft PowerPoint MVP
    Amazing Free PowerPoint Tutorials
    http://www.pptalchemy.co.uk/powerpoi...tutorials.html

  7. #7
    VBAX Newbie
    Joined
    Sep 2017
    Posts
    4
    Location
    I certainly hope my mention was not taken critically at all. I sincerely appreciate your help and level of response.


  8. #8
    VBAX Master
    Joined
    Feb 2007
    Posts
    2,093
    Location
    Don't worry it wasn't.

    Sometimes i just type the code of the top of my head confident I know it will work and sometimes I trip up!
    John Wilson
    Microsoft PowerPoint MVP
    Amazing Free PowerPoint Tutorials
    http://www.pptalchemy.co.uk/powerpoi...tutorials.html

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •