Checking segment visible length Wordfast Classic

From Wordfast Wiki
Jump to: navigation, search

The following macro does the same as the previous macro, but this time, the visible length of text is compared rather than just the number of characters. Note that a segment’s visible length depends on its font.

Sub CheckRealLengthOfText()

'This macro warns the user if the target segment is over 130% of the source's length.

'The *real* visible length of text is compared, not just character count

'(Of course we assume both source and target have the same font and size)

Dim I As Integer, Segment As Range

Static L(1) As Long

For I = 0 To 1

If I = 0 Then

Set Segment = ActiveDocument.Bookmarks("WfSource").Range

Else

Set Segment = ActiveDocument.Bookmarks("WfTarget").Range

End If

Selection.Start = Segment.Start: Selection.End = Selection.Start

Do While Selection.Start < Segment.End - 2

Selection.MoveStart wdLine: Selection.MoveEnd , -1

L(I) = L(I) + Selection.Information(wdHorizontalPositionRelativeToTextBoundary)

Selection.MoveStart , 1

Loop

Next

'Here, "1.3" means 130%. Change this figure as needed.

If (L(1) > L(0) * 1.3) Then

If MsgBox("Target text length is over 130% that of source target." + vbCr + vbCr + "Get back to the segment and correct it?", vbYesNo, "Wordfast") = vbYes Then

Selection.Bookmarks.Add "WfStop"

End If

End If

End Sub

 Back to Wordfast Classic User Manual