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

On Wed, 28 Dec 2005 16:01:02 -0500, Jay Freedman
wrote:

On Tue, 27 Dec 2005 20:23:26 -0800, LurfysMa
wrote:
Excellent! Thanks.

Here's my latest version. I have some questions at the end.


You're really getting into this! Good stuff... I'll just throw in a
couple of suggestions about your code before I get to the questions.


....snip...

'Define the colors to be used
vaColors = Array(wdRed, wdGreen, wdBlack)

'Find out if the user wants random or repeating colors
Const sPrompt As String = "Click on:" & vbCrLf & _
"Yes = random colors" & vbCrLf & _
"No = repeating colors"
Const sTitle As String = "Random Character Colors Macro"
sOption = MsgBox(sPrompt, vbYesNoCancel, sTitle)
If sOption vbYes And sOption vbNo Then 'If neither yes or no,
exit


It would be simpler here to write
If sOption = vbCancel Then


I wasn't sure if Yes, No, and Cancel were the only possibilities. I
just tried the Esc key and the little "X" icon and they both return a
"2" just like Cancel. I just felt safer testing for the values I knew
could be returned and allowing anything else (that I may not have
known about) to cause an exit.

So, unless there's so reason to change it, I think I'll leave it as
is.

2. I am testing for certain characters, such as space, CR and LF, so I
can skip them. Otherwise, the repeating pattern gets off. I should
probably add others such as tab. Is there a good way to test the
current character against a list (without doing separate compares) or
is there a way to test if it is a printable character (a-z, 0-9, or
certain specials (!#$%...)?


You can test against a list by replacing

If oChar.Text = " " Or oChar.Text = vbCr Or oChar.Text = vbLf Then

with

For Each oChar In Selection.Characters
If oChar.Text Like "[A-Za-z0-9!#$%*]" Then


Perfect. That was just what I was looking for.

I was able to get the letters and numbers to work, but ran into
trouble with a few of the special characters:

For single quote, I tried "[A-Za-z0-9']" and "[A-Za-z0-9]'". Neither
worked. With the quote ouside the brackets, no characters were
selected. The help mentions special provisions for []?#*, but not for
the quotes.

For double quote, similar results. I tried "[A-Za-z0-9""]" and
"[A-Za-z0-9]""".

The help warns about "*?#" and the brackets, but this string worked
just fine: "[A-Za-z0-9[*?#]". I could not find a way to make "]" work,
however. I tried "[A-Za-z0-9]]".



Thanks for all the help. Now I am off to read up on user forms to get
that MsgBox impersonator working.

--
Running Word 2000 SP-3 on Windows 2000