For a Range.Paragraph - what is its width?

T

Tony Jollans

The width is the distance from the start of the furthest left line to the
end of the furthest right line, and only in context, which means, I think,
that you must work with the Selection.

This (VBA) has not been tested thoroughly but should get you started:

Dim SelEnd As Long
Dim Min As Long, Max As Long
Min = 1000000 ' any big number
With Selection
SelEnd = .End
.Collapse wdCollapseStart
Do
If .Information(wdHorizontalPositionRelativeToPage) < Min Then
Min = .Information(wdHorizontalPositionRelativeToPage)
End If
.EndKey wdLine
If .Information(wdHorizontalPositionRelativeToPage) > Max Then
Max = .Information(wdHorizontalPositionRelativeToPage)
End If
.MoveRight wdCharacter, 1
If .End = .Document.Range.End Then Exit Do
Loop While .End < SelEnd
End With
MsgBox "Width is " & Max - Min & " points."

This works on the lines spanned by the selection - you'll need to change it
to work with the paragraph(s).
 
T

Tony Jollans

After posting I realised that there are circumstances where the result, even
if arguably 'correct', might not be very useful. Text partially wrapped
round pictures, or flowing over page boundaries when in newspaper columns,
for example.
 
D

David Thielen

Thank you - I keep forgetting about .Information()



The width is the distance from the start of the furthest left line to the
end of the furthest right line, and only in context, which means, I think,
that you must work with the Selection.

This (VBA) has not been tested thoroughly but should get you started:

Dim SelEnd As Long
Dim Min As Long, Max As Long
Min = 1000000 ' any big number
With Selection
SelEnd = .End
.Collapse wdCollapseStart
Do
If .Information(wdHorizontalPositionRelativeToPage) < Min Then
Min = .Information(wdHorizontalPositionRelativeToPage)
End If
.EndKey wdLine
If .Information(wdHorizontalPositionRelativeToPage) > Max Then
Max = .Information(wdHorizontalPositionRelativeToPage)
End If
.MoveRight wdCharacter, 1
If .End = .Document.Range.End Then Exit Do
Loop While .End < SelEnd
End With
MsgBox "Width is " & Max - Min & " points."

This works on the lines spanned by the selection - you'll need to change it
to work with the paragraph(s).


david@[email protected]
Windward Reports -- http://www.WindwardReports.com
me -- http://dave.thielen.com

Cubicle Wars - http://www.windwardreports.com/film.htm
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top