View Single Post
 
Old 03-23-2018, 04:42 AM
catflap's Avatar
catflap catflap is offline Windows 7 64bit Office 2013
Advanced Beginner
 
Join Date: Aug 2015
Location: UK
Posts: 77
catflap is on a distinguished road
Default Resizing fonts in a text box

Hi

After a mail merge to a new document, I need to make sure all the text in a text box fits without overflowing. This I can achieve with the following code which loops though all the text boxes, checks if they overflow, and if so keeps reducing the font by one point until they fit:

Code:
Dim oShp As Shape
    For Each oShp In ActiveDocument.Shapes
        If oShp.Type = msoTextBox Then
            
            Do While ActiveDocument.Shapes(oShp.Name).TextFrame.Overflowing
                ActiveDocument.Shapes(oShp.Name).TextFrame.TextRange.Font.Size = ActiveDocument.Shapes(oShp.Name).TextFrame.TextRange.Font.Size - 1
            Loop
            
        End If
    Next
Things come unstuck however when the text box has more than one font size.

Does anyone know how I could loop though the lines in the text box (so I could resize them one at a time)? - there's only ever one font size per line, so this would work.

Or is there a better way maybe?
Reply With Quote