Supercharge your PowerPoint productivity with
Supercharge your PPT Productivity with PPTools - Click here to learn more.

Proud member of

PPTools

Image Export converts PowerPoint slides to high-quality images.

PPT2HTML exports HTML even from PowerPoint 2010 and 2013, gives you full control of PowerPoint HTML output, helps meet Section 508 accessibility requirements

Merge Excel data into PowerPoint presentations to create certificates, awards presentations, personalized presentations and more

Resize your presentations quickly and without distortion

Language Selector switches the text in your presentation from one language to another

FixLinks prevents broken links when you distribute PowerPoint presentations

Shape Styles brings styles to PowerPoint. Apply complex formatting with a single click.

How many lines in the text box?

Problem

You're programmatically adding text to a text box but need to know when the text box gets over a predetermined size.

Knowing just the text you're plugging into the text box, it's hard to guess how many lines the text box will occupy.

This function will tell you:

Solution

Function LineCount(oSh As Shape) As Long

    ' return zero if no text, -1 if error
    LineCount = 0
    On Error GoTo ErrorHandler
    With oSh
        If .HasTextFrame Then
            If .TextFrame.HasText Then
                LineCount = .TextFrame.TextRange.Lines.Count
            End If
        End If
    End With

NormalExit:
    Exit Function
ErrorHandler:
    LineCount = -1
    Resume NormalExit

End Function

Sub TestLineCount()
    '  Use currently selected shape 
    Debug.Print LineCount(ActiveWindow.Selection.ShapeRange(1))

End Sub

See How do I use VBA code in PowerPoint? to learn how to use this example code.

Search terms:


Did this solve your problem? If so, please consider supporting the PPT FAQ with a small PayPal donation.
Page copy protected against web site content infringement by Copyscape Contents © 1995 - 2022 Stephen Rindsberg, Rindsberg Photography, Inc. and members of the MS PowerPoint MVP team. You may link to this page but any form of unauthorized reproduction of this page's contents is expressly forbidden.

Supercharge your PPT Productivity with PPTools

content authoring & site maintenance by
Friday, the automatic faq maker (logo)
Friday - The Automatic FAQ Maker

How many lines in the text box?
http://www.pptfaq.com/FAQ00610_How_many_lines_in_the_text_box-.htm
Last update 07 June, 2011
Created: