P. 1
Wordfast 5.9 Manual

Wordfast 5.9 Manual

|Views: 694|Likes:
Published by hjpserra

More info:

Published by: hjpserra on Dec 28, 2011
Copyright:Attribution Non-commercial

Availability:

Read on Scribd mobile: iPhone, iPad and Android.
download as PDF, TXT or read online from Scribd
See more
See less

06/17/2013

pdf

text

original

The following macro attempts to rebuild a DOC-like document from a TXT document where
all lines unconditionally end with a paragraph mark.
Text copied from the Internet, or from PDF files, suffer from this common problem.
Note that there is no sure-fire way of "guessing" how paragraphs should be rebuilt. The
following macro uses a few methods that usually give good results, rebuilding most
paragraphs correctly. But the final result must be visually checked before professional use.

Sub TextToDoc()

Dim S As Selection, D1 As Range, D2 As Range, IsPara As Boolean, T As String

If Windows.Count = 0 Then MsgBox "Sorry, no document open": Exit Sub

Set S = ActiveWindow.Selection: Set D1 = S.Range: Set D2 = S.Range
S.End = 0

Do While S.Start < S.StoryLength - 1

' Turn off screen refresh for better speed
Application.ScreenUpdating = False

Wordfast manual

Version 4

117

IsPara = False

' We store the last letter of the line into the string T

S.MoveEndUntil vbCr: T = Trim(S.Text): T = Right(T, 1)

' A first attempt to determine if we do have an end of paragraph:
' the line ends with an end-of-sentence

If InStr(".!?", T) > 0 Then IsPara = True

If S.End < S.StoryLength - 3 Then
D1.SetRange S.End + 1, S.End + 2

If IsPara Then D2.SetRange S.End - 1, S.End Else D2.SetRange S.End - 2, S.End - 1

' If the last character of the line is lowercase and the first character of the next

line is uppercase,

' we'll assume we've got a real paragraph.
' Disable this for languages that capitalize a lot, like German etc.

If D2.Characters(1).Case = wdLowerCase And D1.Characters(1).Case = wdUpperCase Then

IsPara = True

' if the font name or size varies from the current line to the next, we'll also assume
' there's a new paragraph. Very often the case with text copied from PDF; not
' relevant with Txt files.

If S.Font.Name <> D1.Font.Name Then IsPara = True
If S.Font.Size <> D1.Font.Size Then IsPara = True

End If

' If we do not have a paragraph, then join the two lines into one and move on

If Not IsPara Then
S.Start = S.End: S.Delete: S.InsertAfter " "

Else

S.InsertParagraphAfter: S.MoveStart wdParagraph, 1: S.MoveStart wdParagraph, 1

End If

Loop

S.End = 0

MsgBox "Text to Doc conversion finished. Please check the document."
End Sub

You're Reading a Free Preview

Download
scribd
/*********** DO NOT ALTER ANYTHING BELOW THIS LINE ! ************/ var s_code=s.t();if(s_code)document.write(s_code)//-->