www.multilingual.ch - English translations & proofreading - WWW Search Interfaces for Translators
TranslateFaster terminology management macros

 


by Tanya Harvey Ciampi

These macros work in MS Word 97

This is a trial version, my very first attempt at a few macros to speed up some of the repetitive tasks involved in translation, so I make no guarantees as to its working properly on other PCs! Any sort of feedback will be much appreciated!

Click here to download now for free and see what you think!

TranslateFaster.zip

(latest version: 17.8.2002)

Contains the following files:

TranslateFaster.dot
TranslateFasterUC.dot  [UC=uppercase]
TranslateFaster_README.doc
TranslateFaster_test_glossary.doc
TranslateFaster_test_document_to_be_translated.doc


After downloading and unzipping TranslateFaster.zip, print out the README file!

Having trouble? Email me at:

TranslateFaster.dot (the TranslateFaster global template) contains various macros, which are described in the README file, along with the instructions on how to install the template.

 

 

The CODE for the individual macros that constitute the TranslateFaster global template is provided below (in case you wish to install the macros individually as opposed to installing them all together using the global template TranslateFaster.zip).

(Once you have installed the macros individually through the alternative technique of copying and pasting the code that will appears below, you will need to add a macro button in your toolbar or in your right-click menu to run the macro.)

TranslateFaster.dot
For source language English, Italian, French, Spanish etc.
TranslateFasterUC.dot
For source language German etc.

TFCreateNewGlossary
TFTranslateFromGlossary
TFGetFromGlossary
TFSearchGlossary
TFAddToGlossary
TFReplaceAllDown
TFDeleteToFullStop

TFCreateNewGlossary (UC)
TFTranslateFromGlossary (UC)
TFGetFromGlossary (UC)
TFSearchGlossary (UC)
TFAddToGlossary (UC)
TFReplaceAllDown (UC)
TFDeleteToFullStop (UC)

 

NOTE: The document that you need to translate must be a Word document.

 

TFCreateNewGlossary

What the macro does

This macro creates a new glossary in the required format (i.e. a Word document containing a table with two columns, no extra text, spaces or paragraph marks before/after the table; no extra spaces or paragraph marks before or after each term) and prompts you to begin entering terms: Enter source language terms in the left column and target language terms (translations) in the right column. To enter new lines manually select "Table/Insert row".

How to set up the macro

1. Select and copy the text of the macro shown below: Copy only the material that appears between the lines of asterisks; DO NOT copy extra blank lines or the asterisks themselves.

**********cut here (do not include this line) **********

On Error GoTo MainStop
' Arrange windows
Windows.Arrange
Documents.Add
ActiveDocument.Tables.Add Range:=Selection.Range, NumRows:=1, NumColumns:=2
' Go to document to be translated
Dim AnzahlFenster As Integer
Dim NummerAktivesFenster As Integer
AnzahlFenster = Application.Windows.Count
NummerAktivesFenster = Application.ActiveWindow.Index
If AnzahlFenster > NummerAktivesFenster Then
Application.ActiveWindow.Next.Activate
Else
Application.Windows(1).Activate
End If
' Arrange windows placing glossary below
Windows.Arrange
' Return to glossary
Dim AnzahlFenster1 As Integer
Dim NummerAktivesFenster1 As Integer
AnzahlFenster1 = Application.Windows.Count
NummerAktivesFenster1 = Application.ActiveWindow.Index
If AnzahlFenster1 > NummerAktivesFenster1 Then
Application.ActiveWindow.Next.Activate
Else
Application.Windows(1).Activate
End If
MsgBox "Close all other MS Word documents and have open only your document to be translated and this glossary. To begin building your glossary, enter one SOURCE LANGUAGE term in the LEFT column, and its TRANSLATION in the RIGHT colum (no extra spaces, hard returns etc.). When finished, save glossary to your hard drive and return to your document. TIP: Create a different glossary for each subject field."
MainStop:
If Err.Number <> 0 Then
MsgBox "First open the document that you need to translate!"
End If

**********cut here (do not include this line) **********

2. In the menu bar at the top of your window in Word, click on the Tools menu. Click on Macro, then on Macros in the sub-menu.

3. The Macros dialog box will open. Type the name "CreateNewGlossary" for the macro in the "Macro name:" field.

4. Click the Create button.

5. A window titled "Microsoft Visual Basic – Normal – [New Macros (Code)]" will open. In the window that appears, find the line of text that reads: Macro created [Today’s Date] by [Your Name]

6. Paste the macro lines that you copied in Step 1 into the Visual Basic window, at the spot where the input cursor is blinking.

7. Save your macro by clicking the Save button (diskette icon) on the toolbar.

8. Close the whole Visual Basic window. Your macro is now installed.

 

TFTranslateFromGlossary

What the macro does

This macro is a sort of "machine translation" programme: it works its way through your text, replacing any source language terms that are present in your glossary with the corresponding target language terms.

This macro works from the top of your glossary down, so it is important that terms are entered in your glossary following the proper procedure (see AddToGlossary macro).

Both your text to be translated and your glossary must be Word documents; your glossary must have the format described above. Full stops and other punctuation can cause problems, so try to avoid them.

How to set up the macro

Same procedure as above but use the code below instead and change the name in red:

**********cut here (do not include this line) **********

On Error GoTo MainStop
If Documents.Count <> 2 Then
WordBasic.MsgBox "Close all Word documents and open only your Word glossary and your Word document to be translated!"
Exit Sub
End If
ReDim Liste1__$(WordBasic.CountWindows() - 1) ' List of documents available
ReDim Liste2__$(WordBasic.CountWindows() - 1) ' List of documents available
Dim ChoixDoc1$ ' Glossary
Dim ChoixDoc2$ ' Text to be translated
Dim TrouvePhrase ' The phrase searched for has been found
Dim A$ ' Phrase in glossary
Dim b$ ' Phrase in text to be translated
Dim i ' Counter
Dim x ' Dialogue box return value
' Fills in two lists with available documents
For i = 1 To WordBasic.CountWindows()
Liste1__$(i - 1) = WordBasic.[WindowName$](i)
Liste2__$(i - 1) = WordBasic.[WindowName$](i)
Next
' Declaration in dialogue box no. 1
WordBasic.BeginDialog 644, 126, "Select documents"
WordBasic.Text 16, 14, 65, 13, "Glossary:", "Texte1"
WordBasic.Text 16, 49, 49, 13, "Text:", "Texte2"
WordBasic.DropListBox 165, 16, 452, 30, Liste1__$(), "ListeDéroul1"
WordBasic.DropListBox 165, 51, 452, 30, Liste2__$(), "ListeDéroul2"
WordBasic.OKButton 217, 90, 88, 21
WordBasic.CancelButton 339, 90, 88, 21
WordBasic.EndDialog
Dim dlg As Object: Set dlg = WordBasic.CurValues.UserDialog
ChoixDoc:
' Display dialogue box
x = WordBasic.Dialog.UserDialog(dlg, -1)
' In case of errors
' On Error Goto Erreur
' If the user has clicked on OK, then
If x = -1 Then
' Call glossary ChoixDoc1$
ChoixDoc1$ = Liste1__$(dlg.ListeDéroul1)
' Call text to be translated ChoixDoc2$
ChoixDoc2$ = Liste2__$(dlg.ListeDéroul2)
' If the glossary is different from the text to be translated, then
If ChoixDoc1$ <> ChoixDoc2$ Then
WordBasic.WindowArrangeAll
' Declaration in confirmation dialogue box
WordBasic.BeginDialog 153, 123, 411, 119, "Confirm"
WordBasic.Text 10, 6, 382, 73, "Replace the terms present in your glossary : <" + ChoixDoc1$ + "> in your text : <" + ChoixDoc2$ + ">", "Texte1"
WordBasic.OKButton 88, 89, 88, 21
WordBasic.CancelButton 233, 89, 88, 21
WordBasic.EndDialog
Set dlg = WordBasic.CurValues.UserDialog
Set dlg = WordBasic.CurValues.UserDialog
' Display confirmation dialogue box
x = WordBasic.Dialog.UserDialog(dlg, -1)
' If the user clicks on OK, then
If x = -1 Then
' Activate the glossary
WordBasic.Activate ChoixDoc1$
' Position the cursor at the top of the glossary
WordBasic.StartOfColumn 0
WordBasic.StartOfRow 0
' Until the end of the document, do...
' Remove any previous selection
If WordBasic.SelType() = 2 Then WordBasic.SelType 1
WordBasic.StartOfRow
' Select the current phrase
WordBasic.SelectCurSentence
' Call current phrase a$
A$ = WordBasic.[Selection$]()
While WordBasic.AtEndOfDocument() = 0 And WordBasic.[RTrim$](A$) <> ""
' Next phrase
WordBasic.NextCell
WordBasic.SelectCurSentence
b$ = WordBasic.[Selection$]()
' Activate text to be translated
WordBasic.Activate ChoixDoc2$
' Position cursor at the top of the text to be translated
WordBasic.StartOfDocument
' Remove any previous selection
If WordBasic.SelType() = 2 Then WordBasic.SelType 1
WordBasic.EditReplace Find:=A$, Replace:=b$, MatchCase:=0, WholeWord:=1, ReplaceAll:=1, Format:=1
' Activate the glossary
WordBasic.Activate ChoixDoc1$
WordBasic.NextCell
' Remove any previous selection
If WordBasic.SelType() = 2 Then WordBasic.SelType 1
WordBasic.StartOfRow
' Select the current phrase
WordBasic.SelectCurSentence
' Call the current phrase a$
A$ = WordBasic.[Selection$]()
Wend
' Activate the text to be translated
WordBasic.Activate ChoixDoc2$
' Position cursor at the top of the text to be translated
WordBasic.StartOfDocument
' Display message that translation is complete
WordBasic.MsgBox "Translation complete..."
End If
Else
' Display message
WordBasic.MsgBox "Attention: The glossary and the text to be translated cannot be the same document!"
' Return to the dialogue box for selecting glossary and text to be translated
GoTo ChoixDoc
End If
End If
' End without errors
GoTo Fin
' Handling of errors by displaying an error message
Erreur:
WordBasic.MsgBox "Incorrect parameters..."
Fin:
MainStop:
If Err.Number <> 0 Then
MsgBox "An error has occurred! Possible cause: No document open (Open ONLY your text to be translated and your glossary)"
End If

**********cut here (do not include this line) **********

 

TFGetFromGlossary

What the macro does

This macro saves you a lot of switching from file to file and typing (or cutting & pasting) in search of terms that may or may not be present in your glossary: it helps you search your glossary, retrieve existing terms and enter new ones. All you have to do is highlight the word in your text that you wish to retrieve from your glossary and then run the macro: your term will be searched for automatically in your glossary:

  • if the word is present on its own in your glossary you can retrieve it and replace it in the remainder of your text;
  • if the word is not present on its own you will be prompted to enter it:
    -  if your term is present but as part of a phrase, it will be placed directly below the phrase in question.
    -  If your term is not present anywhere in your glossary, it will be placed either at the bottom (if it is a single word) or at the top of your glossary (if it is a phrase).

How to set up the macro

Same procedure as above but use the code below instead and change the name in red:

**********cut here (do not include this line) **********

On Error GoTo MainStop
If Documents.Count <> 2 Then
WordBasic.MsgBox "Close all Word documents and open only your Word glossary and your Word document to be translated. In your text, highlight the SOURCE LANGUAGE term that you wish to retrieve from your glossary, then click again!"
Exit Sub
End If
Dim theTerm As String ' SL term
Dim theTermLC As String ' SL term but all lower case
Dim b$ ' TL term
Dim c$ ' content of each cell containing the SL term
Dim WordOrPhrase As Integer
' Tile the two open windows - glossary and document to be translated
Windows.Arrange
' If the selection is an insertion point
If Selection.Type = wdSelectionIP Then
MsgBox "You need to select the SOURCE LANGUAGE TERM that you wish to retrieve from your glossary."
Exit Sub
End If
' If the selection is NOT an insertion point and therefore a word or phrase
If Selection.Type <> wdSelectionIP Then
theTerm = Selection.Text
End If
' Trim theTerm to remove any spaces after it
theTerm = Trim(theTerm)
WordOrPhrase = Selection.Words.Count
Selection.Copy
' Go to glossary
Dim AnzahlFenster As Integer
Dim NummerAktivesFenster As Integer
AnzahlFenster = Application.Windows.Count
NummerAktivesFenster = Application.ActiveWindow.Index
If AnzahlFenster > NummerAktivesFenster Then
Application.ActiveWindow.Next.Activate
Else
Application.Windows(1).Activate
End If
' Go to top of document
Selection.HomeKey Unit:=wdStory
' Select column to be searched, i.e. column no. 1
Selection.SelectColumn
Selection.Find.ClearFormatting
With Selection.Find
' Search for theTerm
.Text = theTerm
.Forward = True
' Stop at each term found
.Wrap = wdFindStop
.Format = False
.MatchCase = False
.MatchWholeWord = True
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
' Find SL term in glossary
Selection.Find.Execute
' If SL term not found anywhere in glossary
If Selection.Find.Found = False Then
' Move down to remove highlighting of selection
Selection.MoveDown Unit:=wdLine, Count:=1
' Ask user whether he wants to enter a translation in the glossary
Dim y ' Return value of dialogue box
Dim glosdlg As Object: Set glosdlg = WordBasic.CurValues.UserDialog
WordBasic.BeginDialog 153, 123, 411, 119, "Enter translation in glossary"
WordBasic.Text 10, 6, 382, 73, "<" + theTerm$ + "> is not in your glossary. Add it now?"
WordBasic.OKButton 88, 89, 88, 21
WordBasic.CancelButton 233, 89, 88, 21
WordBasic.EndDialog
Set glosdlg = WordBasic.CurValues.UserDialog
Set glosdlg = WordBasic.CurValues.UserDialog
' User answer
y = WordBasic.Dialog.UserDialog(glosdlg, -1)
' If the user clicks the OK button then
If y = -1 Then
' If the term to be added is a phrase
If WordOrPhrase = 1 Then
' If the term to be added is a single word
' Add the term at the bottom of the glossary
' ADDTOGLOSSARY 1 BEGINS HERE
Selection.EndKey Unit:=wdStory
Selection.InsertRows 1
Selection.HomeKey Unit:=wdLine
Selection.TypeText Text:=theTerm
Selection.MoveRight Unit:=wdCell
' ADDTOGLOSSARY 1 ENDS HERE
Else
' ADDTOGLOSSARY 1 BEGINS HERE
' Add the term at the top of the glossary
Selection.HomeKey Unit:=wdStory
Selection.InsertRows 1
Selection.HomeKey Unit:=wdLine
Selection.TypeText Text:=theTerm
Selection.MoveRight Unit:=wdCell
' ADDTOGLOSSARY 1 ENDS HERE
End If
Else
' DONOTHING BEGINS HERE
Dim AnzahlFenster2 As Integer
Dim NummerAktivesFenster2 As Integer
AnzahlFenster2 = Application.Windows.Count
NummerAktivesFenster2 = Application.ActiveWindow.Index
If AnzahlFenster2 > NummerAktivesFenster2 Then
Application.ActiveWindow.Next.Activate
Else
Application.Windows(1).Activate
End If
Selection.MoveRight Unit:=wdCharacter, Count:=1
Exit Sub
' DONOTHING ENDS HERE
End If
' If term has been found in glossary, run the check loop to locate SL term on its own not as part of longer phrase
Else
' First go to beginning of line
Selection.HomeKey Unit:=wdLine
Do
' Find term in glossary
Selection.Find.ClearFormatting
With Selection.Find
.Text = theTerm
.Forward = True
.Wrap = wdFindStop
.Format = False
.MatchCase = False
.MatchWholeWord = True
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
Selection.Find.Execute
' Copy entire cell content and call it c$
Selection.MoveUp Unit:=wdParagraph, Count:=1
Selection.MoveDown Unit:=wdParagraph, Count:=1, Extend:=wdExtend
Selection.MoveLeft Unit:=wdWord, Count:=1, Extend:=wdExtend
c$ = WordBasic.[Selection$]()
' Compare SL term with entire cell content to check whether they are the same
' to make sure our SL term is not part of a longer phrase
' Change all letters to lower case for the purpose of comparing theTerm and c$
theTermLC = LCase(theTerm)
c$ = LCase(c$)
If c$ = theTermLC Then
' GETFROMGLOSSARY BEGINS HERE
' Go and get translation from column no. 2 and call it b$
' Go back to document
Selection.MoveRight Unit:=wdCell
b$ = WordBasic.[Selection$]()
' Ask user where he wants to replace the term
Dim x ' Return value of dialogue box
Dim dlg As Object: Set dlg = WordBasic.CurValues.UserDialog
WordBasic.BeginDialog 153, 123, 411, 119, "Replace term"
WordBasic.Text 10, 6, 382, 73, "<" + theTerm$ + "> = <" + b$ + "> Replace everywhere in text below?"
WordBasic.OKButton 88, 89, 88, 21
WordBasic.CancelButton 233, 89, 88, 21
WordBasic.EndDialog
Set dlg = WordBasic.CurValues.UserDialog
Set dlg = WordBasic.CurValues.UserDialog
' User answer
x = WordBasic.Dialog.UserDialog(dlg, -1)
' If the user clicks the OK button then
If x = -1 Then
' REPLACETHISEVERYWHERE BEGINS HERE
Dim AnzahlFenster1 As Integer
Dim NummerAktivesFenster1 As Integer
AnzahlFenster1 = Application.Windows.Count
NummerAktivesFenster1 = Application.ActiveWindow.Index
If AnzahlFenster1 > NummerAktivesFenster1 Then
Application.ActiveWindow.Next.Activate
Else
Application.Windows(1).Activate
End If
' Replace all
Selection.MoveLeft Unit:=wdCharacter, Count:=1
Selection.Find.ClearFormatting
Selection.Find.Replacement.ClearFormatting
With Selection.Find
.Text = theTerm
.Replacement.Text = b$
.Forward = True
.Wrap = wdFindStop
.Format = False
.MatchCase = False
.MatchWholeWord = True
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
Selection.Find.Execute Replace:=wdReplaceAll
' REPLACETHISEVERYWHERE ENDS HERE
' If the user clicks the Cancel button then
Else
' DONOTHING BEGINS HERE
Dim AnzahlFenster3 As Integer
Dim NummerAktivesFenster3 As Integer
AnzahlFenster3 = Application.Windows.Count
NummerAktivesFenster3 = Application.ActiveWindow.Index
If AnzahlFenster3 > NummerAktivesFenster3 Then
Application.ActiveWindow.Next.Activate
Else
Application.Windows(1).Activate
End If
Selection.MoveRight Unit:=wdCharacter, Count:=1
Exit Sub
' DONOTHING ENDS HERE
End If
' GETFROMGLOSSARY ENDS HERE
Exit Sub
End If
' Deselect cell content by pressing End key so search continues downwards
Selection.EndKey Unit:=wdLine
If Selection.Find.Found = False Then
' Ask user whether he wants to enter translation in glossary for term not found alone
Dim z ' Return value of dialogue box
Dim glossdlg As Object: Set glossdlg = WordBasic.CurValues.UserDialog
WordBasic.BeginDialog 153, 123, 411, 119, "Enter translation in glossary"
WordBasic.Text 10, 6, 382, 73, "<" + theTerm$ + "> is not in your glossary. Add it now?"
WordBasic.OKButton 88, 89, 88, 21
WordBasic.CancelButton 233, 89, 88, 21
WordBasic.EndDialog
Set glossdlg = WordBasic.CurValues.UserDialog
Set glossdlg = WordBasic.CurValues.UserDialog
' User answer
z = WordBasic.Dialog.UserDialog(glossdlg, -1)
' If the user clicks the OK button then
If z = -1 Then
' ADDTOGLOSSARY 2 BEGINS HERE
' Search from bottom up for terms containing my term and place my term below
Selection.EndKey Unit:=wdStory
Selection.MoveUp Unit:=wdLine, Count:=1
' Select column to be searched, i.e. column no. 1
Selection.SelectColumn
Selection.Find.ClearFormatting
With Selection.Find
.Text = theTerm
.Replacement.Text = ""
.Forward = False
.Wrap = wdFindStop
.Format = False
.MatchCase = False
.MatchWholeWord = True
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
Selection.Find.Execute
' Select current cell to move down to cell below
Selection.MoveUp Unit:=wdParagraph, Count:=1
Selection.MoveDown Unit:=wdParagraph, Count:=1, Extend:=wdExtend
Selection.MoveDown Unit:=wdLine, Count:=1
Selection.HomeKey Unit:=wdLine
Selection.InsertRows 1
Selection.HomeKey Unit:=wdLine
Selection.TypeText Text:=theTerm
Selection.MoveRight Unit:=wdCharacter, Count:=1
' ADDTOGLOSSARY 2 ENDS HERE
Exit Sub
' If the user clicks the Cancel button then
Else
' DONOTHING BEGINS HERE
Dim AnzahlFenster4 As Integer
Dim NummerAktivesFenster4 As Integer
AnzahlFenster4 = Application.Windows.Count
NummerAktivesFenster4 = Application.ActiveWindow.Index
If AnzahlFenster4 > NummerAktivesFenster4 Then
Application.ActiveWindow.Next.Activate
Else
Application.Windows(1).Activate
End If
Selection.MoveRight Unit:=wdCharacter, Count:=1
Exit Sub
' DONOTHING ENDS HERE
End If
End If
' Move to cell below and highlight remainder of column no. 1 to be searched
Selection.MoveUp Unit:=wdParagraph, Count:=1
Selection.MoveDown Unit:=wdParagraph, Count:=1, Extend:=wdExtend
Selection.MoveDown Unit:=wdLine, Count:=1
Selection.EndKey Unit:=wdStory, Extend:=wdExtend
Selection.MoveUp Unit:=wdLine, Count:=1, Extend:=wdExtend
Loop Until Selection.Find.Found = False
End If
MainStop:
If Err.Number <> 0 Then
MsgBox "An error has occurred! (Possible cause: Glossary not open)"
End If

**********cut here (do not include this line) **********

 

TFSearchGlossary

What the macro does

This macro searches the source language terms in your glossary to locate a specific term. All instances will be found, including phrases containing your term.

How to set up the macro

Same procedure as above but use the code below instead and change the name in red:

**********cut here (do not include this line) **********

On Error GoTo MainStop
If Documents.Count <> 2 Then
WordBasic.MsgBox "Close all Word documents and open only your Word glossary and your Word document to be translated. In your text, highlight the SOURCE LANGUAGE term that you wish to search for in your glossary, then click again!"
Exit Sub
End If
Windows.Arrange
Dim A$ ' SL term
Dim b$ ' TL term
Dim theTerm As String ' SL term
' If the selection is an insertion point
If Selection.Type = wdSelectionIP Then
MsgBox "You need to select the SOURCE LANGUAGE TERM that you wish to retrieve from your glossary."
Exit Sub
End If
' If the selection is NOT an insertion point and therefore a word or phrase
If Selection.Type <> wdSelectionIP Then
theTerm = Selection.Text
End If
' Trim theTerm to remove any spaces after it
theTerm = Trim(theTerm)
Selection.Copy
' Go to glossary
Dim AnzahlFenster As Integer
Dim NummerAktivesFenster As Integer
AnzahlFenster = Application.Windows.Count
NummerAktivesFenster = Application.ActiveWindow.Index
If AnzahlFenster > NummerAktivesFenster Then
Application.ActiveWindow.Next.Activate
Else
Application.Windows(1).Activate
End If
' Go to top of document
Selection.HomeKey Unit:=wdStory
' Select column to be searched, i.e. column no. 1
Selection.SelectColumn
Selection.Find.ClearFormatting
With Selection.Find
' Search for theTerm
.Text = theTerm
.Forward = True
.Wrap = wdFindStop
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
Selection.Find.Execute
' If SL term not found anywhere in glossary
If Selection.Find.Found = False Then
' Move down to remove highlighting of selection
Selection.MoveDown Unit:=wdLine, Count:=1
MsgBox "<" + theTerm$ + "> was not found amongst the SOURCE LANGUAGE terms in your glossary."
GoTo ReturnToDocument
' If SL term was found in glossary
Else
Do
' Get entire content of cell in column no. 1 and call it a$
Selection.MoveUp Unit:=wdParagraph, Count:=1
Selection.MoveDown Unit:=wdParagraph, Count:=1, Extend:=wdExtend
Selection.MoveLeft Unit:=wdWord, Count:=1, Extend:=wdExtend
A$ = WordBasic.[Selection$]()
' Go and get translation from column no. 2 and call it b$
Selection.MoveRight Unit:=wdCell
b$ = WordBasic.[Selection$]()
' Move back to cell in column 1 so that remainder of column 1 can be highlighted
' for search to continue downwards (see instructions later on)
Selection.MoveLeft Unit:=wdCell
' Ask user whether he wishes to continue search
Dim y ' Return value of dialogue box
Dim searchdlg As Object: Set searchdlg = WordBasic.CurValues.UserDialog
WordBasic.BeginDialog 153, 123, 411, 119, "Search SL terms in glossary"
WordBasic.Text 10, 6, 382, 73, "<" + A$ + "> = <" + b$ + ">. Continue search?"
WordBasic.OKButton 88, 89, 88, 21
WordBasic.CancelButton 233, 89, 88, 21
WordBasic.EndDialog
Set searchdlg = WordBasic.CurValues.UserDialog
Set searchdlg = WordBasic.CurValues.UserDialog
' User answer
y = WordBasic.Dialog.UserDialog(searchdlg, -1)
' If the user clicks the OK button then
If y <> -1 Then
GoTo ReturnToDocument
End If
If y = -1 Then
' Move to cell below and highlight remainder of column no. 1 to be searched
Selection.MoveUp Unit:=wdParagraph, Count:=1
Selection.MoveDown Unit:=wdParagraph, Count:=1, Extend:=wdExtend
Selection.MoveDown Unit:=wdLine, Count:=1
Selection.EndKey Unit:=wdStory, Extend:=wdExtend
Selection.MoveUp Unit:=wdLine, Count:=1, Extend:=wdExtend
Selection.Find.ClearFormatting
With Selection.Find
' Search for theTerm
.Text = theTerm
.Forward = True
.Wrap = wdFindStop
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
Selection.Find.Execute
' Until no more instances are found in column no. 1...
If Selection.Find.Found = False Then
' Move down to remove highlighting of selection
Selection.MoveDown Unit:=wdLine, Count:=1
MsgBox "No more instances of <" + theTerm$ + "> were found amongst the SOURCE LANGUAGE terms in your glossary."
GoTo ReturnToDocument
End If
End If
' ... or Until the user clicks the Cancel button
Loop Until y <> -1
End If
ReturnToDocument:
' Go back to document
Dim AnzahlFenster1 As Integer
Dim NummerAktivesFenster1 As Integer
AnzahlFenster1 = Application.Windows.Count
NummerAktivesFenster1 = Application.ActiveWindow.Index
If AnzahlFenster1 > NummerAktivesFenster1 Then
Application.ActiveWindow.Next.Activate
Else
Application.Windows(1).Activate
End If
MainStop:
If Err.Number <> 0 Then
MsgBox "An error has occurred! (Possible cause: Glossary not open)"
End If

**********cut here (do not include this line) **********

 

TFAddToGlossary

What the macro does

This macro saves you a lot of switching from file to file and typing (or cutting & pasting) to check whether your glossary already contains a specific term before you enter it: your term is automatically searched for:

  • if your term is present on its own in your glossary, you will be informed;
  • if your term is present but as part of a phrase, it will be placed directly below the phrase in question;
  • If your term is not present, it will be placed either at the bottom of your glossary (if it is a single word) or at the top of your glossary (if it is a phrase).

This procedure is important in order to ensure that your glossary maintains the structure required for the TranslateFromGlossary macro to work properly.

How to set up the macro

Same procedure as above but use the code below instead and change the name in red:

**********cut here (do not include this line) **********

On Error GoTo MainStop
If Documents.Count <> 2 Then
WordBasic.MsgBox "Close all Word documents and open only your Word glossary and your Word document to be translated. In your text, highlight the SOURCE LANGUAGE term that you wish to add to your glossary, then click again!"
Exit Sub
End If
Dim theTerm As String ' SL term
Dim theTermLC As String ' SL term all in lower case
Dim c$ ' content of each cell containing the SL term
Dim WordOrPhrase As Integer
' Tile the two open windows - glossary and document to be translated
Dim backtodoc As Integer ' go back to document? 1=yes
backtodoc = 0
Windows.Arrange
' If the selection is an insertion point
If Selection.Type = wdSelectionIP Then
MsgBox "You need to select the SOURCE LANGUAGE TERM that you wish to add to your glossary."
Exit Sub
End If
' If the selection is NOT an insertion point and therefore a word or phrase
If Selection.Type <> wdSelectionIP Then
' If there is an error of any sort go to MainStop
theTerm = Selection.Text
End If
' Trim theTerm to remove any spaces after it
theTerm = Trim(theTerm)
WordOrPhrase = Selection.Words.Count
Selection.Copy
' Go to glossary
Dim AnzahlFenster As Integer
Dim NummerAktivesFenster As Integer
AnzahlFenster = Application.Windows.Count
NummerAktivesFenster = Application.ActiveWindow.Index
If AnzahlFenster > NummerAktivesFenster Then
Application.ActiveWindow.Next.Activate
Else
Application.Windows(1).Activate
End If
' Go to top of document
Selection.HomeKey Unit:=wdStory
' Select column to be searched, i.e. column no. 1
Selection.SelectColumn
' Find SL term in glossary
Selection.Find.ClearFormatting
With Selection.Find
' Search for theTerm
.Text = theTerm
.Forward = True
' Stop at end of document
.Wrap = wdFindStop
.Format = False
.MatchCase = False
.MatchWholeWord = True
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
Selection.Find.Execute
' If SL term not found anywhere in glossary
If Selection.Find.Found = False Then
' If the term to be added is a phrase
If WordOrPhrase = 1 Then
' If the term to be added is a single word
' Add the term at the bottom of the glossary
' ADDTOGLOSSARY 1 BEGINS HERE
Selection.EndKey Unit:=wdStory
Selection.InsertRows 1
Selection.HomeKey Unit:=wdLine
Selection.TypeText Text:=theTerm
Selection.MoveRight Unit:=wdCell
' ADDTOGLOSSARY 1 ENDS HERE
Else
' ADDTOGLOSSARY 1 BEGINS HERE
' Add the term at the top of the glossary
Selection.HomeKey Unit:=wdStory
Selection.InsertRows 1
Selection.HomeKey Unit:=wdLine
Selection.TypeText Text:=theTerm
Selection.MoveRight Unit:=wdCell
' ADDTOGLOSSARY 1 ENDS HERE
End If
' If SL term has been found in glossary
' run the check loop to locate SL term on its own not as part of longer phrase
Else
' First go to beginning of document
Selection.HomeKey Unit:=wdStory
' Select column to be searched, i.e. column 1
Selection.SelectColumn
Do
' Find term in glossary
Selection.Find.ClearFormatting
With Selection.Find
.Text = theTerm
.Forward = True
.Wrap = wdFindStop
.Format = False
.MatchCase = False
.MatchWholeWord = True
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
Selection.Find.Execute
' Copy entire cell content and call it c$
Selection.MoveUp Unit:=wdParagraph, Count:=1
Selection.MoveDown Unit:=wdParagraph, Count:=1, Extend:=wdExtend
Selection.MoveLeft Unit:=wdWord, Count:=1, Extend:=wdExtend
c$ = WordBasic.[Selection$]()
' Compare SL term with entire cell content to check whether they are the same
' to make sure our SL term is not part of a longer phrase
' Change all letters to lower case for the purpose of comparing theTerm and c$
theTermLC = LCase(theTerm)
c$ = LCase(c$)
' If theTerm has been found on its own
If c$ = theTermLC Then
MsgBox "<" + theTerm$ + "> is already in your glossary."
backtodoc = backtodoc + 1
GoTo ReturnToDocument
End If
' Move to cell below and highlight remainder of column no. 1 to be searched
Selection.MoveUp Unit:=wdParagraph, Count:=1
Selection.MoveDown Unit:=wdParagraph, Count:=1, Extend:=wdExtend
Selection.MoveDown Unit:=wdLine, Count:=1
Selection.EndKey Unit:=wdStory, Extend:=wdExtend
Selection.MoveUp Unit:=wdLine, Count:=1, Extend:=wdExtend
Loop Until Selection.Find.Found = False
' ADDTOGLOSSARY 2 BEGINS HERE
' Search from bottom up for terms containing my term and place my term below
Selection.EndKey Unit:=wdStory
Selection.MoveUp Unit:=wdLine, Count:=1
' Select column to be searched, i.e. column no. 1
Selection.SelectColumn
Selection.Find.ClearFormatting
With Selection.Find
.Text = theTerm
.Replacement.Text = ""
.Forward = False
.Wrap = wdFindStop
.Format = False
.MatchCase = False
.MatchWholeWord = True
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
Selection.Find.Execute
' Select current cell to move down to cell below
Selection.MoveUp Unit:=wdParagraph, Count:=1
Selection.MoveDown Unit:=wdParagraph, Count:=1, Extend:=wdExtend
Selection.MoveDown Unit:=wdLine, Count:=1
Selection.HomeKey Unit:=wdLine
Selection.InsertRows 1
Selection.HomeKey Unit:=wdLine
Selection.TypeText Text:=theTerm
Selection.MoveRight Unit:=wdCharacter, Count:=1
' ADDTOGLOSSARY 2 ENDS HERE
End If
MainStop:
If Err.Number <> 0 Then
MsgBox "An error has occurred! (Possible cause: Glossary not open)"
End If
ReturnToDocument:
' Go back to document
If backtodoc <> 0 Then
Dim AnzahlFenster1 As Integer
Dim NummerAktivesFenster1 As Integer
AnzahlFenster1 = Application.Windows.Count
NummerAktivesFenster1 = Application.ActiveWindow.Index
If AnzahlFenster1 > NummerAktivesFenster1 Then
Application.ActiveWindow.Next.Activate
Else
Application.Windows(1).Activate
End If
End If

**********cut here (do not include this line) **********

 

TFReplaceAllDown

What the macro does

This macro speeds up the process of replacing in the remainder of your text all instances of the source language term that you have just entered in your glossary with the target language term that you have just entered alongside it.

How to set up the macro

Same procedure as above but use the code below instead and change the name in red:

**********cut here (do not include this line) **********

On Error GoTo MainStop
If Documents.Count <> 2 Then
WordBasic.MsgBox "Close all Word documents and open only your Word glossary and your Word document to be translated. In your glossary, highlight the TARGET LANGUAGE term that you wish to replace in your text, then click again!"
Exit Sub
End If
Dim A As String ' SL term
Dim b As String ' TL term
' Copy entire content of TL term cell in column 2 and call it b$
Selection.MoveUp Unit:=wdParagraph, Count:=1
Selection.MoveDown Unit:=wdParagraph, Count:=1, Extend:=wdExtend
Selection.MoveLeft Unit:=wdWord, Count:=1, Extend:=wdExtend
b$ = WordBasic.[Selection$]()
' Copy entire content of SL term cell in column 1 and call it a$
Selection.HomeKey Unit:=wdLine
Selection.MoveLeft Unit:=wdCell
A$ = WordBasic.[Selection$]()
' REPLACETHISEVERYWHERE BEGINS HERE
' Return to document to be translated
Dim AnzahlFenster1 As Integer
Dim NummerAktivesFenster1 As Integer
AnzahlFenster1 = Application.Windows.Count
NummerAktivesFenster1 = Application.ActiveWindow.Index
If AnzahlFenster1 > NummerAktivesFenster1 Then
Application.ActiveWindow.Next.Activate
Else
Application.Windows(1).Activate
End If
' Replace all a (SL term) with b (TL term) downwards in document
' First move left to begin with current term
Selection.MoveLeft Unit:=wdCharacter, Count:=1
Selection.Find.ClearFormatting
Selection.Find.Replacement.ClearFormatting
With Selection.Find
.Text = A$
.Replacement.Text = b$
.Forward = True
.Wrap = wdFindStop
.Format = False
.MatchCase = False
.MatchWholeWord = True
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
Selection.Find.Execute Replace:=wdReplaceAll
' REPLACETHISEVERYWHERE ENDS HERE
Selection.Find.ClearFormatting
' Move cursor after first replacement made
With Selection.Find
.Text = b$
.Forward = True
.Wrap = wdFindStop
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
Selection.Find.Execute
Selection.MoveRight Unit:=wdCharacter, Count:=1
MainStop:
If Err.Number <> 0 Then
MsgBox "An error has occurred! (Possible causes: Glossary not open / You need to highlight the TL term in the glossary that you wish to replace in your document)"
End If

**********cut here (do not include this line) **********

 

TFDeleteToFullStop

What the macro does

This macro deletes the text from the position of your cursor up to the next full stop. It can be useful when you are translating a document, typing in your translation over the source text.

How to set up the macro

Same procedure as above but use the code below instead and change the name in red:

**********cut here (do not include this line) **********

Selection.Extend
Selection.Find.ClearFormatting
With Selection.Find
.Text = "."
.Replacement.Text = ""
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
Selection.Find.Execute
Selection.MoveLeft Unit:=wdCharacter, Count:=1
Selection.Delete

**********cut here (do not include this line) **********

 

 

 

Print this page!

 

Back / Tools for Translators / Home / Site Map

http://www.multilingual.ch
Web design by Tanya Harvey Ciampi