Consulting

Results 1 to 4 of 4

Thread: VBA to resize font in headers and body

  1. #1
    VBAX Regular
    Joined
    Jun 2021
    Posts
    17
    Location

    VBA to resize font in headers and body

    Hello - i hope someone can help me to update the codes below to do the resize correctly. I am trying to resize the font of any header and then the body/content as well as on the1st slide. based on my codes below, whenever the size of the font changes in the deck, the codes don't work correctly. Basically i need three separate VBA to do the work. see my codes below. hoping an expert can help!! thank you so much!!


    1. Change Header font size on every slide to 44


    Sub ChangeHeaderFontSize()
    Dim sld As Slide
    Dim shp As Shape

    For Each sld In ActivePresentation.Slides
    For Each shp In sld.Shapes
    If shp.HasTextFrame = True Then
    If shp.TextFrame.HasText = True Then
    If shp.TextFrame.TextRange.Font.Size = 24 Then
    shp.TextFrame.TextRange.Font.Size = 44

    End If
    End If
    End If

    Next
    Next

    End Sub


    2. Change content font size of every slide to 32






    Sub ChangeContentFontSize()
    Dim sld As Slide
    Dim shp As Shape

    For Each sld In ActivePresentation.Slides
    For Each shp In sld.Shapes
    If shp.HasTextFrame = True Then
    If shp.TextFrame.HasText = True Then
    If shp.TextFrame.TextRange.Font.Size = 15 Then
    shp.TextFrame.TextRange.Font.Size = 32
    End If
    End If
    End If

    Next
    Next

    End Sub




    3. Change header font size to 60 just on 1st Slide

    Sub Change1stSlideHeaderFontSize()
    Application.ActivePresentation.Slides(1) _
    .Shapes(1).TextFrame.TextRange.Font _
    .Size = 60

    End Sub

  2. #2
    VBAX Sage
    Joined
    Apr 2007
    Location
    United States
    Posts
    8,711
    Location
    This only does it on placeholders, not other types of shapes or tables

    I didn't bother to test for the current font size (like in your macros)


    Option Explicit
    
    
    Sub test()
        Dim oPres As Presentation
        Dim oSlide As Slide
        Dim oShape As Shape
    
    
        Set oPres = ActivePresentation
    
    
        For Each oSlide In oPres.Slides
            For Each oShape In oSlide.Shapes
                With oShape
                    If .Type <> msoPlaceholder Then GoTo NextShape
                    If Not .HasTextFrame Then GoTo NextShape
                    If Not .TextFrame.HasText Then GoTo NextShape
            
                    If (.PlaceholderFormat.Type = ppPlaceholderTitle) Or _
                        (.PlaceholderFormat.Type = ppPlaceholderCenterTitle) Or _
                        (.PlaceholderFormat.Type = ppPlaceholderVerticalTitle) Then
                        '3. Change header font size to 60 just on 1st Slide
                        '1. Change Header font size on every slide to 44
                        .TextFrame.TextRange.Font.Size = IIf(oSlide.SlideNumber = 1, 60, 44)
                            
                    Else
                        '2. Change content font size of every slide to 32
                        .TextFrame.TextRange.Font.Size = 32
                    End If
                End With
            
    NextShape:
            Next
    NextSlide:
        Next
    
    
    End Sub
    ---------------------------------------------------------------------------------------------------------------------

    Paul


    Remember: Tell us WHAT you want to do, not HOW you think you want to do it

    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) / 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
    VBAX Regular
    Joined
    Jun 2021
    Posts
    17
    Location
    Thank you Paul. It doesn't work well for the First Slide. How about we disregard the change to 1st slide and just VBA to change the font size of all content to 32, and change all header to 44 in all slides except the 1st slide? I tried to edit the codes you had and didn;t work. hope you can help. thank you!!!

  4. #4
    VBAX Sage
    Joined
    Apr 2007
    Location
    United States
    Posts
    8,711
    Location
    Quote Originally Posted by rwc1023 View Post
    Thank you Paul. It doesn't work well for the First Slide. How about we disregard the change to 1st slide and just VBA to change the font size of all content to 32, and change all header to 44 in all slides except the 1st slide? I tried to edit the codes you had and didn;t work. hope you can help. thank you!!!
    We can do that, but it worked for me as far as the first slide

    Attach a small presentation where it doesn't work
    ---------------------------------------------------------------------------------------------------------------------

    Paul


    Remember: Tell us WHAT you want to do, not HOW you think you want to do it

    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) / 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

Tags for this Thread

Posting Permissions

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