Consulting

Results 1 to 14 of 14

Thread: Delete empty placeholders

  1. #1

    Delete empty placeholders

    Hello friends,

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

    Please help me in this regard.

    Regards,
    Bala.

  2. #2
    VBAX Sage
    Joined
    Apr 2007
    Location
    United States
    Posts
    8,726
    Location
    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

  3. #3
    VBAX Master
    Joined
    Feb 2007
    Posts
    2,094
    Location
    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

  4. #4
    VBAX Sage
    Joined
    Apr 2007
    Location
    United States
    Posts
    8,726
    Location
    Do a check for HasTextFrame.
    Good point, and 'Good-er' catch.

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

    Paul

  5. #5
    VBAX Master
    Joined
    Feb 2007
    Posts
    2,094
    Location
    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

  6. #6
    VBAX Sage
    Joined
    Apr 2007
    Location
    United States
    Posts
    8,726
    Location
    Didn't take it as critical at all

    Took it as valuable feedback and a useful tip

    Paul

  7. #7
    VBAX Master
    Joined
    Feb 2007
    Posts
    2,094
    Location
    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

  8. #8

    Thanks

    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.

  9. #9
    VBAX Master
    Joined
    Feb 2007
    Posts
    2,094
    Location
    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

  10. #10

    Please help

    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.

  11. #11

    Yes John

    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.

  12. #12
    VBAX Master
    Joined
    Feb 2007
    Posts
    2,094
    Location
    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

  13. #13

    Hi John

    Hi John,

    This code works perfect. Thanks for the code.

    What is the use of .HasTextframe?

    Thanks for the clarification and all.

    Reg,
    Bala.

  14. #14
    VBAX Master
    Joined
    Feb 2007
    Posts
    2,094
    Location
    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

Posting Permissions

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