determine height of text box in MS Word 2003

I have the following code to create a text box around some text and set its width:
Selection.ShapeRange(1).Width = InchesToPoints(7.3)

Open in new window

Now I need to determine the length or number of lines in the selection to determine the height of the text box:
     Selection.ShapeRange(1).Height = ??

Any ideas?  TIA
LVL 39
Who is Participating?
GrahamSkanConnect With a Mentor RetiredCommented:
This might be what you need:
Dim sh As Shape
Set sh = Selection.ShapeRange(1)
sh.Width = InchesToPoints(7.3)
sh.TextFrame.AutoSize = True

Open in new window

Personally I don't think I would do it like that, but this does work.

Selection.Font.Size * Selection.Paragraphs(1).Range.ComputeStatistics(wdStatisticLines) + (Selection.ParagraphFormat.SpaceAfter * Selection.Paragraphs(1).Range.ComputeStatistics(wdStatisticLines) - 1)

Open in new window

thenelsonAuthor Commented:
That worked!

I used:
Selection.ShapeRange(1).Height = (Selection.Range.ComputeStatistics(wdStatisticLines) + 1) * 12

but your suggestion of:
sh.TextFrame.AutoSize = True

I believe is more reliable and cleaner.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.