May 4, 2012

Preparing MS Word text with a specific highlight color

If the Catholic Church decides its needs an official backup for Jerome as the patron saint of translators (and in these times of tribulation, one cannot have enough divine help I suppose), Dave Turner of ASAP Traduction gets my vote. His CodeZapper macros for Microsoft Word have saved us so many thousands of hours of grief dealing with rogue tags in RTF and MS Word files, which screw up TM and termbase matches and make work very difficult, and other more recent contributions also offer useful support. He is the first one in my mind when I see a problem and think "There ought to be a macro for that!"

Dave's latest contribution was part of an old discussion about preparing texts for translation in which the text to translate was marked by a highlight color. As I remember the original discussion, there were several highlight colors, and only one was to be chosen for work. Usually, if text of a certain color is to be hidden or shown in preparing a file for translation with a CAT tool which filters out hidden text, I use the search and replace function in Microsoft Word. That does not work for selecting a highlight of a specific color. You need to use a macro for that, and I no longer have the VBA skills to handle that myself. I can adapt a working macro, but no way I can manage a good one from scratch unless I spend a few days or more re-learning the skills of a decade ago.

So I was very happy when I saw his answer to the problem in the memoQ yahoogroups forum, which I have reproduced here with just a  minor change to reflect the usual highlighting I encounter:

Sub HideExceptYellow()
'
' Translation assistance macro
' by Dave Turner
' http://asap-traduction.com/

Dim rDcm As Range
ActiveDocument.Range.Font.Hidden = True
Set rDcm = ActiveDocument.Range
With rDcm.Find
.Text = ""
.Highlight = True
.Forward = False
While .Execute
If rDcm.HighlightColorIndex = wdYellow Then
rDcm.HighlightColorIndex = wdNoHighlight
rDcm.Font.Hidden = False
rDcm.Collapse Direction:=wdCollapseStart
rDcm.Start = ActiveDocument.Range.Start
End If
Wend
End With
Set rDcm = ActiveDocument.Range
Options.DefaultHighlightColorIndex = wdYellow
With rDcm.Find
.Text = ""
.Font.Hidden = False
.Forward = False
.Replacement.Highlight = True
.Execute Replace:=wdReplaceAll
End With
End Sub
In MS Word 2003 and earlier versions, the macro can be created under Tools > Macros > View Macros. Name the macro, then click the Create button to paste in the code. The Run button will execute an existing macro if it is selected.


In MS Word 2007/2010 the same functionality is accessed on the View ribbon with the Macros icon or Alt+F8.

Here's a short video showing the procedure to copy the code into the Normal global template in Microsoft Word, where it is available to all open documents in Word:



To adapt this for another highlight color, just rename the macro and change the designation of the color (wdYellow). The macro can be adapted to deal with combinations of highlight colors as well, and similar methods can be used to deal with text colors, though these can be handled by the search and replace dialog.

7 comments:

  1. This doesn't work in Word 2010

    ReplyDelete
  2. Really? That's news to me. Word 2010 is all I've got these days. But then I suppose nuclear power is safe too....

    ReplyDelete
  3. Good afternoon, Kevin,

    I have just updated TransTools, a free suite of commands for translators, adding a new command similar to Dave Turner's called Hide / Unhide Text. This command offers a number of options to mark text as hidden prior to importing Word documents into CAT tools, or to 'unhide' all text in a document after the translated document is generated. You can "hide" text which is highlighted or "hide" everything except highlighted text, so it is well suited for most scenarios when preparing dual-language documents or previously translated documents with new text added. While Dave's command works well in most situations, it cannot process headers and footers, for instance, or text marked with several highlight colors. A detailed overview of this command is available at http://www.translatortools.net/word-hideunhide.html .

    Best regards,
    Stanislav

    ReplyDelete
  4. Same here, macro hides everything it seems.

    ReplyDelete
  5. Very impressed with this macro, thanks.
    I wanted to hide only the yellow text, which I managed to do, but then the recursion (or whatever) seems to struggle and fall over on my really big documents. thanks though ...

    ReplyDelete
  6. Hi, landed on ur site through googling. I used the macro and followed the step by step procedure as shown in the youtube video. But when I run the macro all the text in the word document disappears - even the one that is not highlighted YELLOW. Any help will be appreciated. Thanks. By the way wonderful explanation and thanks again.

    ReplyDelete
  7. Thank you! How about if it's another way around? For example the highlighted text of s specific color should be deleted/hidden? Please reply. Thanks again! :)

    ReplyDelete

Notice to spammers: your locations are being traced and fed to the recreational target list for my new line of chemical weapon drones :-)