Results 1 to 3 of 3
  1. #1
    3 Star Lounger
    Join Date
    Aug 2001
    Location
    Jeddah, Saudi Arabia
    Posts
    243
    Thanks
    0
    Thanked 1 Time in 1 Post

    Text length in points (2000)

    I'm trying to find out the length of a selection in points. The FitTextWidth method seems to be what I'm looking for BUT.

    I select some text then

    MsgBox Selection.FitTextWidth returns zero.

    I select some text then

    Selection.FitTextWidth=CentimetersToPoints(10)
    MsgBox Selection.FitTextWidth return 283.5, the correct value.

    It would appear that the FitTextWidth method needs to be prompted. I would set it to 10 then set it back but I don't know what the length was in the first place.

    I don't want to have to get into Device Contexts and Font Metrics if I can help it.

    Any help would be greatly appreciated as always.

    Regards,

    Kevin Bell

  2. #2
    5 Star Lounger
    Join Date
    May 2001
    Location
    Stuttgart, Baden-W, Germany
    Posts
    931
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Text length in points (2000)

    Hi Kevin,

    I think the FitTextWidth-method is made for far-east languages like Chinese; if you use it to set the text width, it will space your letters, and that is frowned upon in typography (well... at least in Europe <img src=/S/wink.gif border=0 alt=wink width=15 height=15>).

    Use Selection.Information instead:
    <pre>Sub LengthOfSelection()
    Dim myRange As Range
    Dim PosX1, PosX2, PosY1, PosY2
    Set myRange = Selection.Range
    Selection.Collapse Direction:=wdCollapseStart
    PosX1 = Selection.Information(wdHorizontalPositionRelative ToTextBoundary)
    PosY1 = Selection.Information(wdVerticalPositionRelativeTo TextBoundary)
    myRange.Select
    Selection.Collapse Direction:=wdCollapseEnd
    PosX2 = Selection.Information(wdHorizontalPositionRelative ToTextBoundary)
    PosY2 = Selection.Information(wdVerticalPositionRelativeTo TextBoundary)
    myRange.Select
    If PosY2 - PosY1 > 0 Then
    MsgBox "Selection spans " & Selection.Paragraphs.Count & " lines!"
    Else
    MsgBox PosX2 - PosX1, vbOKOnly + vbInformation, "Length (in pt)"
    End If
    End Sub</pre>


    <img src=/S/cheers.gif border=0 alt=cheers width=30 height=16>Klaus

  3. #3
    3 Star Lounger
    Join Date
    Aug 2001
    Location
    Jeddah, Saudi Arabia
    Posts
    243
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: Text length in points (2000)

    Thanks Klaus. That's what I ended up doing.

    I still think there should be an easier way and I'm sure that I remember way back in the mists of time a WordBasic function or property that returned the length in points.

    Looks like another 'feature' that MS decided wasn't neccessary.

    Regards and thanks again.

    Kevin Bell

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •