Quantcast
Channel: ProZ.com Translation Forums
Viewing all articles
Browse latest Browse all 3915

From Ms Word table to TMX file | Complete macro

$
0
0
Forum: CAT Tools Technical Help
Topic: From Ms Word table to TMX file
Poster: Hans Lenting
Post title: Complete macro

Here is the complete macro. It will try to detect the source and target language and if it fails, it will ask you for the language codes.

The macro assumes that the table that you want to convert to TMX has two columns only: the first column contains the source language, the second one the target language.

How to install this macro? There are many instructions on the internet. Here is one: [url removed]

Copy the code below and replace all « with < and all » with >.

Adapt/add language codes where necessary.

Adjust the storage path (this one is for my Desktop on my Mac).

Sub TableToTMX()

Dim rngTemp As Range
Dim tableTemp As Table
Dim strSL As String
Dim strTL As String

'Determine the source and target language
Selection.Tables(1).Columns(1).Select
strSL = Selection.LanguageID
Selection.Tables(1).Columns(2).Select
strTL = Selection.LanguageID

Select Case strSL
Case 1031
strSL = "de-DE"
Case 1033
strSL = "en-US"
Case 1043
strSL = "nl-NL"
Case Else
strSL = InputBox("Type the code for the source language", "Source language selection", "en-GB")
End Select

Select Case strTL
Case 1031
strTL = "de-DE"
Case 1033
strTL = "en-US"
Case 1043
strTL = "nl-NL"
Case Else
strTL = InputBox("Type the code for the target language", "Target language selection", "nl-NL")
End Select

Options.AutoFormatReplaceQuotes = False
Selection.Tables(1).Select
Selection.Copy
Documents.Add
Selection.Paste

Set tableTemp = ActiveDocument.Tables(1)
Set rngTemp = _
tableTemp.ConvertToText(Separator:=wdSeparateByTabs)
Selection.Delete

'Convert ampersand, less than and greater than to markup
Selection.Find.ClearFormatting
Selection.Find.Replacement.ClearFormatting
With Selection.Find
.Text = "&"
.Replacement.Text = "&"
.Forward = False
.Wrap = wdFindAsk
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
Selection.Find.Execute Replace:=wdReplaceAll
With Selection.Find
.Text = ""
.Forward = False
.Wrap = wdFindAsk
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
Selection.Find.Execute Replace:=wdReplaceAll

Selection.Find.ClearFormatting
Selection.Find.Replacement.ClearFormatting
With Selection.Find
.Text = "^p"
.Replacement.Text = _
"^p"
.Forward = False
.Wrap = wdFindAsk
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
Selection.Find.Execute Replace:=wdReplaceAll
Selection.Find.ClearFormatting
Selection.Find.Replacement.ClearFormatting
With Selection.Find
.Text = "^t"
.Replacement.Text = ""
.Forward = False
.Wrap = wdFindAsk
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
Selection.Find.Execute Replace:=wdReplaceAll

Selection.TypeText Text:=""
Selection.HomeKey Unit:=wdStory
Selection.TypeText Text:=""

'Replace placeholder language codes with correct codes
Selection.Find.ClearFormatting
Selection.Find.Replacement.ClearFormatting
With Selection.Find
.Text = "xx-XX"
.Replacement.Text = strSL
.Forward = False
.Wrap = wdFindAsk
.Format = False
.MatchCase = True
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
Selection.Find.Execute Replace:=wdReplaceAll
Selection.Find.ClearFormatting
Selection.Find.Replacement.ClearFormatting
With Selection.Find
.Text = "yy-YY"
.Replacement.Text = strTL
.Forward = False
.Wrap = wdFindAsk
.Format = False
.MatchCase = True
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
Selection.Find.Execute Replace:=wdReplaceAll

'Adjust path below
ActiveDocument.SaveAs2 FileName:="/Users/hl/Desktop/memory.tmx", FileFormat:= _
wdFormatText, Encoding:=65001, LineEnding:=wdLFOnly
End Sub

Viewing all articles
Browse latest Browse all 3915

Trending Articles