VB script to search background colour in Word?
Thread poster: Jan Sundström

Jan Sundström  Identity Verified
Sweden
Local time: 01:39
English to Swedish
+ ...
Feb 27, 2009

Hi all,

I have a Word document that consists of several two-column tables. If it was one long table, it would be no trouble, but there are 50-over separate tables, interspersed with graphical objects and page breaks.

Like this:
---
| English source text (do not touch) | Copy of English source text to be translated |
---
The left column has a blue background, but the actual text formatting is identical in both columns.

I wanted to make a search/replace with the Pattern Matching in Word, that way I could apply tw4WinExternal to the left columns.
But no option exists to search for background colour!

Does anyone know if this would be possible to achieve through writing a VB script?
I found some resources online indicating that it's possible, but I have no clue how to program VB:
http://builder.oflameron.ru/
http://www.tek-tips.com/viewthread.cfm?qid=1442506&page=9

Or do you have other ideas how to solve this nut?!

/J


Direct link Reply with quote
 

Jabberwock  Identity Verified
Poland
Local time: 01:39
Member (2004)
English to Polish
Columns? Feb 27, 2009

It is possible with VBA (I assume you meant it as a Word macro?), but first I would try a different approach: just mark the first column of all tables. But for that I would have to be sure that it is always that particular column which needs to be marked...

If it is so, here's the macro:

Code:


Sub ExternalizeFirstColumn()

For Each aTable In ActiveDocument.Tables
aTable.Columns(1).Select
Selection.Style = "tw4WinExternal"
Next

End Sub




It works here, but of course try it out on a copy...

[Edited at 2009-02-27 19:39 GMT]


Direct link Reply with quote
 

Vito Smolej
Germany
Local time: 01:39
Member (2004)
English to Slovenian
+ ...
why not DO-NOT-TRANSLATE style Feb 27, 2009

Hi Jan:

what you want to do, is taken care of by DO NO TRANSLATE style. Just Mark all those texts you want unchanged as DO_NO_TRANSLATE. I do not know, however, how it looks, when you have to change the style back to the original - but that's the same problem also, when painting everything with tw4WinExternal.

Or am I missing the point?

The gut feeling is "you cant have a cake and eat it too": changing styles is what it says...


Direct link Reply with quote
 

Daniel Grau  Identity Verified
Argentina
English to Spanish
There is a problem with applying styles... Feb 27, 2009

... and that is, the format of the text would be altered. It is better to apply an untranslatable attribute, such as Marching Red Ants, and then enable it in WF preferences. The macro would change from:

Selection.Style = "tw4WinExternal"

to:

Selection.Font.Animation = wdAnimationMarchingRedAnts

After translation (and/or cleanup), you do a Select All and choose Font > Animation > None. In this way, the source format is preserved.

A further refinement would we to add a line below that one, stating:

Selection.LanguageID = wdNoProofing

so the spellckecker won't stop at this text.

Daniel


Direct link Reply with quote
 

Daniel Grau  Identity Verified
Argentina
English to Spanish
DELETED double post Feb 27, 2009



[Edited at 2009-02-27 22:37 GMT]


Direct link Reply with quote
 

Jabberwock  Identity Verified
Poland
Local time: 01:39
Member (2004)
English to Polish
Styles and not Feb 27, 2009

The Red Ants trick works only with WordFast, so it will not be good for Trados (I'm not sure which Jan is using).

If the appearance of the text matters, it is enough to change the properties of the tw4WinExternal style - Trados only looks at the style name, not at particular font properties. Besides, changing one style with another with Find and Replace is rather trivial...


Direct link Reply with quote
 

Daniel Grau  Identity Verified
Argentina
English to Spanish
You are right, it's a WF thing... Feb 28, 2009

... and he does not list it among his software.

As regards this:

changing one style with another with Find and Replace is rather trivial...


A global style replacement won't work if you have two different styles to restore, as in this case, unless you perform it one-by-one.

Daniel


Direct link Reply with quote
 

Jan Sundström  Identity Verified
Sweden
Local time: 01:39
English to Swedish
+ ...
TOPIC STARTER
You can't search for background colour :-( Mar 3, 2009

Jabberwock wrote:
Besides, changing one style with another with Find and Replace is rather trivial...


Vito wrote:
Just Mark all those texts you want unchanged as DO_NO_TRANSLATE.



Hi all,

Thanks a lot for your suggestions so far.
Like Vito guessed however, I'm afraid most of you missed the point!

My problem again:
I have over 50 separate tables in each Word doc.
I know how to mark each table individually and apply a style (or apply hidden text). But I'd have to do it 50 times over every time I get a new file. That's why I'd prefer a macro.

I know how to search/replace in Word based on Pattern Matches (replace one colour with another colour, replace italics with bold, replace one style with another style).

BUT: the problem is that Word doesn't allow searching for background colour! Check it for yourself, I could hardly believe it when I assumed to find the function and it was absent in the search window.

/Jan


Direct link Reply with quote
 

Jabberwock  Identity Verified
Poland
Local time: 01:39
Member (2004)
English to Polish
The macro is right there... Mar 3, 2009

The macro I have given before allows to select the first column of every table and apply the style you want. Automatically, no manual searching required.

The other comments concerned the case when you need to restore the formatting of the source, if it changes (although I believe it is not relevant in this case).


Direct link Reply with quote
 

Jerzy Czopik  Identity Verified
Germany
Local time: 01:39
Member (2003)
Polish to German
+ ...
Do not use styles Mar 3, 2009

but just hidden text formatting and translate in Tageditor.
If you do so, the only action you need after the translation is done is unhide the text. This way you can prevent Tageditor from accessing the text which should not be translated, but don't change the formatting of it. When you unhide it the formatting is exactly as it was before.


Direct link Reply with quote
 

Jabberwock  Identity Verified
Poland
Local time: 01:39
Member (2004)
English to Polish
Hidden text Mar 3, 2009

If you prefer to hide the text instead of styling, replace the line:

Selection.Style = "tw4WinExternal"

with:

Selection.Font.Hidden = True

However, if different font properties are used within the cells, they might be made the same. Macros are somewhat inconsistent in this respect.


Direct link Reply with quote
 


To report site rules violations or get help, contact a site moderator:


You can also contact site staff by submitting a support request »

VB script to search background colour in Word?

Advanced search






Across v6.3
Translation Toolkit and Sales Potential under One Roof

Apart from features that enable you to translate more efficiently, the new Across Translator Edition v6.3 comprises your crossMarket membership. The new online network for Across users assists you in exploring new sales potential and generating revenue.

More info »
SDL Trados Studio 2017 Freelance
The leading translation software used by over 250,000 translators.

SDL Trados Studio 2017 helps translators increase translation productivity whilst ensuring quality. Combining translation memory, terminology management and machine translation in one simple and easy-to-use environment.

More info »



Forums
  • All of ProZ.com
  • Term search
  • Jobs
  • Forums
  • Multiple search