Consulting

Results 1 to 15 of 15

Thread: Referring subtitle of a slide in order to format using VBA PowerPoint

  1. #1

    Referring subtitle of a slide in order to format using VBA PowerPoint

    Hello all,

    I am trying to set the position and formatting of title, subtitle in the slide. I tried doing it using the following code. It works on title but not on subtitle. How can we get reference of subtitle to work on its position, font size etc.

    Sub Titles()
    Dim osld As Slide, oshp As Shape
    For Each osld In ActivePresentation.Slides
    For Each oshp In osld.Shapes
    If oshp.Type = msoPlaceholder Then
    
    If oshp.PlaceholderFormat.Type = ppPlaceholderTitle Then
    With oshp
    .Top = 5
    .Left = 5
    .TextFrame.TextRange.Font.Name = "Times New Roman"
    .TextFrame.TextRange.Font.Size = 24
    End With
    
    ElseIf oshp.PlaceholderFormat.Type = ppPlaceholderSubtitle Then
    With oshp
    .Top = 10
    .Left = 10
    .TextFrame.TextRange.Font.Name = "Times New Roman"
    .TextFrame.TextRange.Font.Size = 18
    End With
    
    End If
    
    
    End If
    
    Next oshp
    Next osld
    End Sub
    Attached Images Attached Images
    Last edited by Paul_Hossler; 09-06-2019 at 09:21 AM. Reason: Added CODE tags

  2. #2
    VBAX Wizard
    Joined
    Apr 2007
    Posts
    6,755
    Location
    Not every slide has a Subtitle placeholder, even if it looks like a subtitle

    1. Is that a true placeholder type Subtitle, or a text box that you're using as a subtitle

    2. Could you use the Master Slide(s) to format the way you want?

    3. Little rearranging and one add


    Option Explicit
    
    Sub Titles()
        Dim oSld As Slide, oShp As Shape
        
        For Each oSld In ActivePresentation.Slides
            For Each oShp In oSld.Shapes
                With oShp
                    If .Type = msoPlaceholder Then
                        Select Case .PlaceholderFormat.Type
                            Case ppPlaceholderTitle, ppPlaceholderCenterTitle   '   <<<<<<<<<<<<<<
                                .Top = 5
                                .Left = 5
                                .TextFrame.TextRange.Font.Name = "Times New Roman"
                                .TextFrame.TextRange.Font.Size = 24
            
                            Case ppPlaceholderSubtitle
                                .Top = 10
                                .Left = 10
                                .TextFrame.TextRange.Font.Name = "Times New Roman"
                                .TextFrame.TextRange.Font.Size = 18
                            End Select
                    End If
                End With
            Next oShp
        Next oSld
    End Sub
    Attached Files Attached Files
    Paul

    ------------------------------------------------------------------------------------------------------------------------
    1. Use [CODE] ....[/CODE ] Tags for readability
    [CODE]PasteYourCodeHere[/CODE ] -- (or paste your code, select it, click [#] button)
    2. Upload an example
    Go Advanced / Attachments - Manage Attachments / Add Files / Select Files / Select the file(s)
    (multiple files can be selected while holding Ctrl key) / Upload Files / Done
    3. Mark the thread as [Solved] when you have an answer
    Thread Tools (on the top right corner, above the first message)
    4. Read the Forum FAQ, especially the part about cross-posting in other forums
    http://www.vbaexpress.com/forum/faq...._new_faq_item3

  3. #3
    I am working on already formatted presentation( not creating it from scratch). Could you please guide me on how to find whether it is "placeholder type Subtitle, or a text box". When I tried to detect this using "selection pane" to see type it is named as " Text placeholder 1, Text placeholder 2"..in many slides.

    In order to use master slide, I am already working on well formatted presentation and moreover first slide doesn't have style as showed in attached picture.



  4. #4
    The code you suggested earlier is behaving same like the one I shared. Only "Title" is altered.

  5. #5
    VBAX Master
    Joined
    Feb 2007
    Posts
    1,879
    Location
    If the Name of the placeholder is "Text placeholder xx" then they are almost certainly NOT SubTitle placeholders but Text Placeholders, In fact except for the Title Slide Layout you will hardly ever see SubTitle Placeholders because they are hard to add!
    John Wilson
    Microsoft PowerPoint MVP
    Amazing Free PowerPoint Tutorials
    http://www.pptalchemy.co.uk/powerpoi...tutorials.html

  6. #6
    VBAX Master
    Joined
    Feb 2007
    Posts
    1,879
    Location
    Why not just reset the Custom Layout?
    John Wilson
    Microsoft PowerPoint MVP
    Amazing Free PowerPoint Tutorials
    http://www.pptalchemy.co.uk/powerpoi...tutorials.html

  7. #7
    VBAX Wizard
    Joined
    Apr 2007
    Posts
    6,755
    Location
    Quote Originally Posted by CuriosityBug View Post
    The code you suggested earlier is behaving same like the one I shared. Only "Title" is altered.
    I expected that since the Textbox that looks like a subtitle for the slide is not a true Subtitle Placeholder

    Is there some property common to all such "subtitle" Textboxes that the macro could check for?

    Attach a small presentation with a couple of slides (remove sensitive data) and indicate which Textboxes that you want to apply a format macro to

    Even if it is an existing presentation, you can still use Masters to control the formatting
    Paul

    ------------------------------------------------------------------------------------------------------------------------
    1. Use [CODE] ....[/CODE ] Tags for readability
    [CODE]PasteYourCodeHere[/CODE ] -- (or paste your code, select it, click [#] button)
    2. Upload an example
    Go Advanced / Attachments - Manage Attachments / Add Files / Select Files / Select the file(s)
    (multiple files can be selected while holding Ctrl key) / Upload Files / Done
    3. Mark the thread as [Solved] when you have an answer
    Thread Tools (on the top right corner, above the first message)
    4. Read the Forum FAQ, especially the part about cross-posting in other forums
    http://www.vbaexpress.com/forum/faq...._new_faq_item3

  8. #8
    Hello John,
    Yes, I guess they are no more "SubTitle placeholders". When I check for type of placeholder(ppPlaceholderType) it is returning a value 1 for both "Title" and "Subtitle".



  9. #9
    VBAX Wizard
    Joined
    Apr 2007
    Posts
    6,755
    Location
    See if you can use this

    http://www.pptfaq.com/FAQ00769_Creating_-Pseudo-Subtitles-.htm


    Paul

    ------------------------------------------------------------------------------------------------------------------------
    1. Use [CODE] ....[/CODE ] Tags for readability
    [CODE]PasteYourCodeHere[/CODE ] -- (or paste your code, select it, click [#] button)
    2. Upload an example
    Go Advanced / Attachments - Manage Attachments / Add Files / Select Files / Select the file(s)
    (multiple files can be selected while holding Ctrl key) / Upload Files / Done
    3. Mark the thread as [Solved] when you have an answer
    Thread Tools (on the top right corner, above the first message)
    4. Read the Forum FAQ, especially the part about cross-posting in other forums
    http://www.vbaexpress.com/forum/faq...._new_faq_item3

  10. #10
    VBAX Master
    Joined
    Feb 2007
    Posts
    1,879
    Location
    That would be very strange

    Type 1 is Title but only one of this type is allowed on a layout. What was your exact code?
    John Wilson
    Microsoft PowerPoint MVP
    Amazing Free PowerPoint Tutorials
    http://www.pptalchemy.co.uk/powerpoi...tutorials.html

  11. #11
    Hello Paul,

    The common element I found is the name in each slide as " text place holder xx". I am not sure about it. Attaching the demo ppt with slides which has two text boxes I want to apply macro.
    Attached Files Attached Files

  12. #12
    John, I attached ppt that could provide clear insight

  13. #13
    VBAX Master
    Joined
    Feb 2007
    Posts
    1,879
    Location
    What you have is a slide with a blank layout. Someone has copy pasted placeholders from the master but this doesn't work so the two shapes are not placeholders at all just normal textboxes. You are going to have a hard time fixing this because it's a mess.
    John Wilson
    Microsoft PowerPoint MVP
    Amazing Free PowerPoint Tutorials
    http://www.pptalchemy.co.uk/powerpoi...tutorials.html

  14. #14
    Thanks for the link Paul. This helped me to get awareness. To position Left and Top, make everything automated this cannot be used I guess.

  15. #15
    Quote Originally Posted by John Wilson View Post
    What you have is a slide with a blank layout. Someone has copy pasted placeholders from the master but this doesn't work so the two shapes are not placeholders at all just normal textboxes. You are going to have a hard time fixing this because it's a mess.
    I removed the other components in slides like table,text boxes for confidentiality. But, the format of title and subtitle is same as shown. My bad to hear this. Thanks for the insight John. At least this taught me something

Posting Permissions

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