View Single Post
  #35   Report Post  
Posted to microsoft.public.word.newusers
LurfysMa
 
Posts: n/a
Default Random letter colors?

On Tue, 03 Jan 2006 10:37:25 -0500, Jay Freedman
wrote:

It looks like I went to bed too early last night. :-)

The implication of the too-terse help topic is that you can't combine
the right bracket with anything else in a pattern that includes a
group. You do have to do two separate comparisons, although they can
be in the same statement:

If (obChar.Text Like "[A-Za-z0-9?[*#]") Or _
(obChar.Text Like "]") Then

or the equivalent

If (obChar.Text Like "[A-Za-z0-9?[*#]") Or _
(obChar.Text = "]") Then


I discovered a way to get all of the letters, numbers, and special
characters, including the curly quotes, with a fairly simply pattern
for use in the Like operator and without needing two compares.

The trick lies in realizing that all of these characters are in order
starting with the space character (decimal 32, hex 20) and ending with
the ~ (decimal 126, hex 7E). I got this information from

http://www.lookuptables.com/

This enables a single range to get everything including all of the
wild card characters, the straight quotes, and the brackets.

"[ -~]"

The code would look something like this:

For Each obChar In Selection.Characters
If obChar.Text Like "[ -~]" Then
obChar.Font.ColorIndex =GetNextColor
End If
Next obChar

To also get the curly quotes (145-149), simply add another range iont
the same group:

"[ -~" & Chr$(145) & "-" & Chr$(148) & "]"

Slick, if I do say so myself.

OK, now someone tell me why this won't work! ;-)

--
Running Word 2000 SP-3 on Windows 2000