Category: Macros

Repetitive tasks can be simplified, and repetitive tasks (e.g. search/replace) performed automatically.

  • Adding a date to the front of the filename of a Word document

    Adding a date to the front of the filename of a Word document

    I frequently receive translations as documents from colleagues with ambiguous filenames like: “Übersetzung.docx” – and more often than not they are for small translation “snippets” – from a couple of sentences to a couple of paragraphs. I like to run a couple of macros in Word before I translate – most notably to change non-breaking hyphens into normal ones.

    In addition though, to help with aligning documents to dates received, I have a little macro that I use that saves the file with a date prefixed into the filename from inside Word. This helps in particular for short snippets that are not translated as separate projects in Trados, but dragged into a project made up of short translations.

    Sub DateFN()
    If ActiveDocument.Name = ActiveDocument.FullName Then
        If Not Application.Dialogs(wdDialogFileSaveAs).Show Then Exit Sub
    End If
        CurrentFormat = ActiveDocument.SaveFormat
        CurrentPathAndName = ActiveDocument.FullName
        CurrentPath = Replace(ActiveDocument.FullName, ActiveDocument.Name, "")
        NewNameSamePath = CurrentPath & Format(Now, "yymmdd") & " - " & ActiveDocument.Name
        ActiveDocument.SaveAs FileName:=NewNameSamePath, FileFormat:=CurrentFormat
        Kill CurrentPathAndName
    End Sub

    Why do I use the YYMMDD date format?

    I chose this particular date format, although YYYYMMDD would work just as well as it is easiest to sort filenames that start with years followed months and then days.

  • Stripping non-breaking hyphens in Word

    Stripping non-breaking hyphens in Word

    The non-breaking hyphen is a useful device. It is a special character that ensures that “Greco-Roman” in “Greco-Roman wrestling” never splits across two lines. Similarly, it helps avoid “gemischte EU-Mutterfinanzholdinggesellschaften” splitting as gemischte EU- / Mutterfinanzholdinggesellschaften (see e.g. Article 1, para. 1 no. 4 BaSAG for a typical usage!) or similar compound nouns in legal translations. In the latter case, if hyphenation is turned on in narrow columns, you end up with some strange-looking lines.

    However, for translators using CAT tools, it can be annoying, with non-breaking hyphens rendered as tags in the source text. This can cause problems in the CAT tool as it will flag the target text as missing a tag. Fortunately there is a simple way in Word to search and replace all non-breaking hyphens, to get around this problem. Once you have mastered this for non-breaking hyphens there are other use cases for other special characters.

    What to do in Word

    There is a wildcard (similar to a regular expression) in Word for finding non-breaking hyphens – which is ^~. To use it, extend the Search/replace dialogue (Ctrl + H) by clicking on “More > >” and then select the wildcards option. Alternatively you can add this wildcard character through the “Special” button at the bottom of this dialogue. Then do a search/replace for all instances.

    Naturally, going through a lot of documents can become a time-consuming process. Help is at hand in the form of a macro. If you use it a bit, it definitely warrants having a Word Macro for this, which appears below.

    Sub ChangeNonBreakHyphen()
    '
    ' ChangeNonBreakHyphen Makro
    ' Converts non-breaking hyphens into a normal hyphen.
    '
        Selection.Find.ClearFormatting
        Selection.Find.Replacement.ClearFormatting
        With Selection.Find
            .Text = "^~"
            .Replacement.Text = "-"
            .Forward = True
            .Wrap = wdFindContinue
            .Format = False
            .MatchCase = False
            .MatchWholeWord = False
            .MatchAllWordForms = False
            .MatchSoundsLike = False
            .MatchWildcards = True
        End With
        Selection.Find.Execute Replace:=wdReplaceAll
    End Sub

    Add it to your macros in Word through the Developer tab. I even have it added to my ribbon tab containing all my translation macros. You may find other special characters that can be treated in a similar manner.

    If you discover a slew of non-breaking hyphens in the middle of your source text in Trados, there is an easy solution. You can clean up the Word document, add it to your translation project again, and run a Perfect Match. afterwards.