Link to home
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
Avatar of Joe Howard
Joe Howard
Flag of United States of America image

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
Avatar of GrahamSkan
GrahamSkan
Flag of United Kingdom of Great Britain and Northern Ireland image

Blurred text
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
Avatar of thenelson
thenelson

ASKER

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!