Log in

View Full Version : [SOLVED:] Delete empty placeholders



balumail75
05-26-2011, 07:30 AM
Hello friends,

How to delete empty placeholders in ppt 2007 with vba code?

Please help me in this regard.

Regards,
Bala.

Paul_Hossler
05-26-2011, 03:51 PM
One way



Option Explicit

Sub DeleteEmptyPlaceholders()
Dim oSlide As Slide
Dim oShape As Shape
For Each oSlide In ActivePresentation.Slides
For Each oShape In oSlide.Shapes
With oShape
If .Type = msoPlaceholder Then
If .TextFrame.TextRange.Length = 0 Then
.Delete
End If
End If
End With
Next
Next
End Sub


Paul

John Wilson
05-27-2011, 12:31 AM
I'm wondering why you want to this though? I would create custom layouts with the placeholders needed.

Paul's code won't work with non text placeholders and shapes with no textframe will crash it. Do a check for HasTextFrame.

Paul_Hossler
05-27-2011, 06:46 AM
Do a check for HasTextFrame.


Good point, and 'Good-er' catch.

I just tested with very simple presentation, and was not very through

Paul

John Wilson
05-27-2011, 08:01 AM
Sorry that came over as a bit critical. It wasn't meant to!

Paul_Hossler
05-27-2011, 12:23 PM
Didn't take it as critical at all

Took it as valuable feedback and a useful tip

Paul
:beerchug:

John Wilson
05-27-2011, 12:25 PM
I could do with a beer right now!

balumail75
05-31-2011, 05:50 AM
I am converting so many charts in ppt 2007 to emf. Most of the charts were created in placeholders. While cutting and pasting thru' vba code, the empty placeholders appear in every slide.

This code clears me that. Thanks for helping me.

Regards,
Bala.

John Wilson
05-31-2011, 05:57 AM
Did you use the exact code I posted before? The emf should paste into the placeholder and not leave it empty?

balumail75
05-31-2011, 06:02 AM
if I run the above code, the error comes as "The specified value is out of range". Please help me.

The placeholders are type of Chart placeholders, text placeholders, after converting the charts to emf pictures.

Please clarifiy, what is the use of .hastextframe?

Thanks for all.

balumail75
05-31-2011, 06:07 AM
Yes John, I used that code. it pasted the placeholders chart in the middle of the slide.

It will be very usefull for me, if I know, how to delete empty placeholders. because, I get lot of ppts, with different layouts applied for each slide.

Thanks for your code and clarification.

John Wilson
05-31-2011, 06:41 AM
Are you SURE they are chart placeholders (They would only show the option to add a chart - nothing else)

This would delete them I think:


Sub DeleteEmptyPlaceholders()
Dim oSlide As Slide
Dim oShape As Shape
Dim i As Integer
For Each oSlide In ActivePresentation.Slides
For i = oSlide.Shapes.Count To 1 Step -1
Set oShape = oSlide.Shapes(i)
With oShape
If .Type = msoPlaceholder Then
If .PlaceholderFormat.ContainedType = 1 Then
' IT IS EITHER A CONTENT/TEXT PLACEHOLDER or ANOTHER TYPE WITH NO CONTENT
If .HasTextFrame Then 'content / text
If .TextFrame.TextRange.Length = 0 Then .Delete
ElseIf .PlaceholderFormat.Type = ppPlaceholderChart Then .Delete
End If
End If
End If
End With
Next i
Next oSlide
End Sub

balumail75
05-31-2011, 06:46 AM
Hi John,

This code works perfect. Thanks for the code.

What is the use of .HasTextframe?

Thanks for the clarification and all.

Reg,
Bala.

John Wilson
05-31-2011, 07:43 AM
Some placeholders (eg chart) do not have a textframe. If you try to check the length of a non existant textframe it would crash SO... Check it's there first.