PDA

View Full Version : Deleting a specific text box



Spktr
10-11-2013, 09:52 PM
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.

John Wilson
10-12-2013, 01:25 AM
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

VABP
09-07-2017, 08:58 AM
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?

John Wilson
09-07-2017, 09:13 AM
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

VABP
09-07-2017, 09:37 AM
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..)

John Wilson
09-07-2017, 10:36 AM
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

VABP
09-07-2017, 11:07 AM
I certainly hope my mention was not taken critically at all. I sincerely appreciate your help and level of response.

:hi:

John Wilson
09-07-2017, 11:50 AM
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!