Shrink Text To Fit Text Box

  • Greetings,
    I would like a lovely bit of code which squashes a font size if it overflows a text box or expands the font if the text is tiny. My text box has word wrapping. I chased the legend of the .font.shrink function around the internet and found the following bit of code, but it doesn't work on my text box.
    Help please.


  • Re: Shrink Text To Fit Text Box


    Hi Andy,
    Sorry, not sure what you mean by an example of a text box. The only text box property selected is word wrap. The user gets to change the text in a the box, the font is 14pt tahoma and which allows three lines each with 16 characters. If the user chooses a string that splills out of the bottom of the box then I want a macro to auto-shrink the text.
    Benny

  • Re: Shrink Text To Fit Text Box


    I am not exactly how you want you code to would but this test routine will resize a textbox.


    [vba]
    For Each oShp In oSld.Shapes
    If oShp.HasTextFrame Then
    sngHeight = oShp.Height
    oShp.TextFrame.AutoSize = ppAutoSizeShapeToFitText
    If oShp.Height > sngHeight Then
    Do
    oShp.TextFrame.TextRange.Font.Size = oShp.TextFrame.TextRange.Font.Size - 1
    If oShp.TextFrame.TextRange.Font.Size = 1 Then Exit Do
    Loop While oShp.Height > sngHeight
    Else
    Do
    oShp.TextFrame.TextRange.Font.Size = oShp.TextFrame.TextRange.Font.Size + 1
    If oShp.TextFrame.TextRange.Font.Size > 72 Then Exit Do
    Loop While oShp.Height < sngHeight
    End If
    oShp.TextFrame.AutoSize = ppAutoSizeNone
    End If
    Next oShp
    [/vba]


    Where on the www did you find .Shrink and .Overflowing examples?

  • Re: Shrink Text To Fit Text Box




    Hi Andy,:):)


    I'm trying to make this one work for PPT files that I export after language conversion in one of the CAT tools. In some of the language pairs the translated content will not fit into the text boxes due to the differences in the language lengths. Therefore, the translated and exported PPTs contain multiple shapes/text boxes that have some content outside the visible areas of such shapes. I was wondering if there is a way to get the newly exported textual content within all shapes/text boxes in the exported PPTs files all shrunk altogether to fit the original sizes of those shapes.


    When I am trying to run the above macros, the macros will stop at 'For Each oShp In oSld.Shapes' and returns an error that an object is required. I am working in MS Office 15.


    Thank you in advance for your help with this!