Sub CleanReviewersFiles()
Dim SourceSeg As String, TargSeg As String, a As Integer
Dim tw As TW4Win.Application, tm As TranslationMemory, Filez As Variant
Dim rev As Revision, doc As Document, j As Long
Dim pos As Integer, pos2 As Integer
Filez = Array("dummy")
[b]Set tw = New TW4Win.Application
tw.TranslationMemory.Open "C:\test.tmw", "automated"
Set tm = tw.TranslationMemory[/b]
'typical Trados jobfile for cleanup:
'[Cleanup]
'LogFile = C:\Trados\TW4Win\cleanup.log
'Files = x
'File1=C:\Trados\TW4Win\demo97.rtf
'...
With Application.FileSearch
.LookIn = InputBox("Path ro reviewer's documents?")
.FileName = "*.*"
.FileType = msoFileTypeWordDocuments
.SearchSubFolders = True
.Execute
End With
'Start writing the Trados job file for automated cleanup
a = FreeFile
Open "C:\cleanjob.log" For Output As a
Print #a, "[Cleanup]"
Print #a, "LogFile=C:\templog.log"
For i = 1 To Application.FileSearch.FoundFiles.Count
Set doc = Documents.Open(Application.FileSearch.FoundFiles(i))
j = 1
doc.TrackRevisions = True
Do
Set rev = doc.Revisions(j)
If InStr(1, rev.Range.Text, "<}") > 0 Then 'look for mid segment marker
SourceSeg = rev.Range.Text
pos = InStr(1, SourceSeg, "{0>")
pos2 = InStr(1, SourceSeg, "<}0{>")
SourceSeg = Mid(SourceSeg, pos + 3, pos2 - 4)
Set rev = doc.Revisions(j + 1) 'Next revision object contains the new text
TargSeg = rev.Range.Text
[b]
tm.Search (SourceSeg)
tm.TranslationUnit.Save TargSeg[/b]
End If
j = j + 1
Loop Until j = doc.Revisions.Count
ReDim Preserve Filez(i)
Filez(i - 1) = doc.FullName
doc.Revisions.AcceptAll
doc.TrackRevisions = False
doc.Close SaveChanges:=True
Next i
'Now write list of files into cleanup job file
Print #a, "Files = " & UBound(Filez)
For i = 0 To UBound(Filez) - 1
Print #a, "File" & i + 1 & " = " & Filez(i)
Next i
Close a
[b]
tm.CleanupFiles "C.\cleanjob.log"
tm.Close
tw.Quit
[/b]
End Sub