Hello friends,
How to delete empty placeholders in ppt 2007 with vba code?
Please help me in this regard.
Regards,
Bala.
Hello friends,
How to delete empty placeholders in ppt 2007 with vba code?
Please help me in this regard.
Regards,
Bala.
One way
[VBA]
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
[/VBA]
Paul
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.
John Wilson
Microsoft PowerPoint MVP
Amazing Free PowerPoint Tutorials
http://www.pptalchemy.co.uk/powerpoi...tutorials.html
Good point, and 'Good-er' catch.Do a check for HasTextFrame.
I just tested with very simple presentation, and was not very through
Paul
Sorry that came over as a bit critical. It wasn't meant to!
John Wilson
Microsoft PowerPoint MVP
Amazing Free PowerPoint Tutorials
http://www.pptalchemy.co.uk/powerpoi...tutorials.html
Didn't take it as critical at all
Took it as valuable feedback and a useful tip
Paul
I could do with a beer right now!
John Wilson
Microsoft PowerPoint MVP
Amazing Free PowerPoint Tutorials
http://www.pptalchemy.co.uk/powerpoi...tutorials.html
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.
Did you use the exact code I posted before? The emf should paste into the placeholder and not leave it empty?
John Wilson
Microsoft PowerPoint MVP
Amazing Free PowerPoint Tutorials
http://www.pptalchemy.co.uk/powerpoi...tutorials.html
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.
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.
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:
[VBA]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[/VBA]
John Wilson
Microsoft PowerPoint MVP
Amazing Free PowerPoint Tutorials
http://www.pptalchemy.co.uk/powerpoi...tutorials.html
Hi John,
This code works perfect. Thanks for the code.
What is the use of .HasTextframe?
Thanks for the clarification and all.
Reg,
Bala.
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.
John Wilson
Microsoft PowerPoint MVP
Amazing Free PowerPoint Tutorials
http://www.pptalchemy.co.uk/powerpoi...tutorials.html