Avatar of thenelson
thenelson asked on

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:
ActiveDocument.Bookmarks("TotalRecommendation").Range.Select
Selection.CreateTextbox
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
Microsoft WordMicrosoft Office

Avatar of undefined
Last Comment
thenelson

8/22/2022 - Mon
Joe Howard

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

ASKER CERTIFIED SOLUTION
GrahamSkan

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
See how we're fighting big data
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question
ASKER
thenelson

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.

Thanks!
Your help has saved me hundreds of hours of internet surfing.
fblack61