Conditional formatting (?): How to bold all text that comes before a colon
December 5, 2011 9:42 PM   Subscribe

Is there a way to make all text at the beginning of a line, preceding a colon, BOLD in Microsoft Word?

Sorry, I did check Google and the Microsoft site first and neither are yielding any results for this (shocker).

So, say you are putting together a glossary (a long one)that is set up like this:

Term: definition etc.

But you want it to look like:

Term: definition etc.

Of course I could go through and manually make each term bold (and yes, I realize I should have done this as I went along but I initially thought I'd be doing this whole thing differently so I didn't bother), but I'd really like to know if there is a shortcut because 1) I am working with A LOT of terms and it could take a while, and 2) I think that this is something that could really come in handy for me in the future anyway. Effectively, it would be some sort of command that tells the computer "Make any text that precedes a colon bold" (for the current document, it wouldn't even have to specify "at the beginning of the line" as I said in my original question, because here there aren't colons anywhere else).

Can't even conceive of how this would be done with Find/Replace, although that is essentially what I'd be doing. Is this the job for a macro?? I know virtually nothing about how those work but it seems like the truly skilled MS Word users can always do magical things with macros.

Any help is appreciated and more details can be provided if needed!
posted by lovableiago to Computers & Internet (11 answers total) 7 users marked this as a favorite
You could do this using VBA (the office scripting language)
posted by askmehow at 9:55 PM on December 5, 2011

This happens automatically for me on all recent versions of MS Word (Windows) when I create a bulleted or numbered list.

1. Create the first list item. Before leaving that item and going to the next line, bold the opening text and the colon.
2. At the end of the item, hit Enter to start the next item. As you start typing, the text will appear bold, up to and including the colon. As you leave the colon, the text goes back to regular weight for the rest of that item.
3. Once all your text is done, select the list and turn off bulleted or numbered list. The bold effect stays.
posted by maudlin at 10:05 PM on December 5, 2011

If colons only occur once per line like that, you could do this in a couple of minutes:
1. Select all.
2. Convert everything to a table using the colon as the column delimiter.
3. Select just the left column.
4. Make it bold.
5. Select the whole table.
6. Convert the entire table back to text, specifying that the column break convert to a tab.
7. Replace each tab with a colon plus a tab.
posted by pracowity at 10:23 PM on December 5, 2011 [4 favorites]

You can use Find/Replace with wildcards. I tried this quickly in Word 2003 and it seemed to work. Didn't check for edge cases or anything, though.

Note: this assumes that each definition is on a new line, and that the only place new lines occur is between definitions. If that isn't true, then you'll need to tweek the following.

1. Open the F/R window
2. Hit the "More" button
3. check "Use Wildcards"
4. in the Find box, type something like (^013[!:]*:)

That will search for any sequence of characters that fits these criteria: a newline followed by any number of characters that are not a colon, followed by a colon.

-- how this works: ^013 represents a newline character. Square brackets tell Word to search for any character defined inside those brackets. An exclamation mark says "anything except the following". So [!:] says "any character that is not a colon". Then the * says "zero or more instances of the preceding character," so 0 or more not-colons. Up to now we have ^013[!:]* -- now we add a colon to the end, because that's the last thing we want our search to match. Then we wrap the whole expression in parentheses, because then you can ...

5. type \1 in the Replace box. \1 matches the first (and in this case, only) parenthesis-wrapped expression in the Find box.

6. While you're still in the Replace box, hit ctrl-B. Under the box, there should now be a line saying something like "Format: Font: Bold, [etc.] "

7. Hit Find Next a few times to make sure you're matching what you want to match!
8. go ahead and start replacing

Wildcard searches are really useful. Unfortunately there's a lot about them that Word doesn't make obvious (such as having to use ^013 to match a newline instead of ^p or ^l, which work for non-wildcard search...)
posted by trig at 2:49 AM on December 6, 2011 [15 favorites]

The "right" way to do this is probably through the Styles and Formatting menu via a custom format.

I would probably use the "make it a table" option suggested above.
posted by gjc at 6:30 AM on December 6, 2011

Yeah, regardless of how you do the replacement, the best way to work is to find and replace the plain-text terms with a character style, not with just bold. If you change your mind later (maybe you want bold plus a larger or different font), you want to be able to redefine the style and instantly change the way all terms look. Do the same for the paragraph -- define a paragraph style to apply to all of them.
posted by pracowity at 8:44 AM on December 6, 2011

@Trig: This seems to be the best option so far. For what it's worth, these glossary definitions are already IN the first column of a two column table (images will go in the second column). Maybe because of it, when i do the F/R with (^013[!:]*:), it's not 'finding' anything.

HOWEVER, when I enter ([!:]*:) and just do Find it goes through and highlights each of my terms, which is exactly what I want (so far). My plan was to have it find these and replace each with a bold version of what's already there.

HOWEVER, when I enter ([!:]*:) in the Replace line and make it bold, it just goes through and puts ([!:]*:) where each of my terms should be! Why can I check the Wildcards option for the Find line and not for replace? Is there a symbol/command I can put in the replace line that basically means "Same as what's above, in the Find line" and indicate for that to be made bold?

I'm so close to the solution here.....!

P.S. When you put parentheses, isn't that basically like putting quote marks around something in computer language? I assumed when I did the find before as you instructed, that I should leave the parentheses out...but I just added them in to see if it will still highlight my terms and it did (same as before) so I am just a tad confused.
posted by lovableiago at 8:57 AM on December 6, 2011

No, you put (^013[!:]*:) in the Find line and you put nothing (no text at all) in the Replace line (except the bold command that appears under the replace line).
posted by pracowity at 9:26 AM on December 6, 2011

BINGO! MANY thanks--I foresee this being a lifesaver in the future...
posted by lovableiago at 10:26 AM on December 6, 2011

(on preview: don't leave the Replace box bold; if you do then the words Find matches will be replaced with nothing, i.e. erased.)

In the Find box, enter this (with parentheses!):


In the Replace box, you want this:


And you want to hit Ctrl-B while you're still in the Replace box (unless Bold is already turned on. If it is, it'll say so right under the Replace box).

[note: if you want to use Styles instead of plain Bold formatting, check out the options in the menu marked Format or something similar (I don't have access to Word at the moment). That menu button should be on the bottom, to the right of a menu button labelled Special or Special Characters, which is also worth checking out.]

Anyway, that's it. Just (^013[!:]*:) in Find and \1 in Replace.


You asked about the parentheses. What happens is that when Word finds a match, it can remember the text it matched. So for example, if you have a line like

Hello: A word used for greeting

then the search expression ^013[!:]*: will match the text "Hello:" (without quotes). If you put parens around the search expression, then not only will Word match that text, but it will also keep it in memory. When you enter \1 in the Replace box, that means "replace with whatever is the first expression stored in memory." In this case that's "Hello:", but next time you hit Find Next, the match might be "Goodbye:" or "What's up:" or whatever.

This is really useful. Say you have a list of book names, like

The Great Gatsby, Fitzgerald
The Wizard of Oz, Baum
The Glory of Regular Expressions, Anon

and you want to turn it into

Great Gatsby, The; Fitzgerald
Wizard of Oz, The; Baum

What you can do is use Find to match for a newline, followed by the word The, followed by a space, any bunch of characters, and finally a comma. The expression you'd use is something like

^013The [!,]*,

But now you want to move the The to the end of the title and put a semicolon after it. But how is Word going to remember what the title was? You tell it to remember by surrounding it with parentheses:

^013The ([!,]*),

That means that everything matched by [!,]* (which should be any character between "The " and the comma) is going to be remembered. How do you refer to it? As \1.

So, in the Replace box, you'd enter

\1, The;

First time you run the search, \1 will refer to "Great Gatsby". Next time, \1 will mean "Wizard of Oz". And so on.

What if you want to remember a bunch of things? Maybe you want to turn a line like

The Great Gatsby, Fitzgerald


Fitzgerald: Great Gatsby, The

In that case, your search expression will want to remember both the author name and the title:

^013The ([!,]*), ([!^013]*)^013

If that's hard to follow, think of it as:

NewlineThe (Title), (Author)Newline

Here you have two parenthesized expressions. Word remembers the first one, ([!,]*) , which matches the title, as \1. It remembers the next one, ([!^013]), matching the author, as \2. And so, in the Replace box, you can enter

\2: \1, The^p

and that will give you the author's name, followed by a colon, followed by a space, followed by the title, followed by a comma, space, the word The, and a newline!

Hope this helps. (If anyone tries this at home, this is off the top of my head -- I haven't tested these particular expressions.)
posted by trig at 10:27 AM on December 6, 2011 [6 favorites]

umm, I meant to say "don't leave the Replace box empty"!
posted by trig at 10:28 AM on December 6, 2011

« Older Song-learning playlist!   |   Posting work I did for a uni course online Newer »
This thread is closed to new comments.