View Single Post
 
Old 01-09-2013, 06:42 PM
Jennifer Murphy's Avatar
Jennifer Murphy Jennifer Murphy is offline Windows XP Office 2007
Competent Performer
 
Join Date: Aug 2011
Location: Silicon Valley
Posts: 234
Jennifer Murphy is on a distinguished road
Default

How about this? It turns any character in CharSet red and anything else green. In practice, it would skip them rather than turn them green.

Code:
Sub TestColorMacro()
Const MyName As String = "TestColorMacro"
Dim msg As String
msg = "Test the set of printable colors. Press Enter to continue or Cancel to abort."
Dim temp
temp = InputBox(msg, MyName, "OK")
If temp = "" Then Exit Sub

'Define the set of printable characters
Dim CharSet As String
CharSet = "ABCDEFGHIJKLMNOPQRSTUVWXYZ" _
        & "abcdefghijklmnopqrstuvwxyz" _
        & "1234567890`~!@#$%^&*()-_=+[]{}\|;:,.<>/?" _
        & "'""" & Chr(145) & Chr(146) & Chr(147) & Chr(148)

Dim obChar As Range
For Each obChar In Selection.Characters
'  'Display the ASCII code
'  msg = obChar & "=" & Asc(obChar)
'  MsgBox msg
  'If the character is in the set, color it red.
  If InStr(CharSet, obChar) > 0 Then
    obChar.Font.Color = RGB(255, 0, 0)
  'Otherwise, color it green
  Else
    obChar.Font.Color = RGB(0, 255, 0)
  End If
Next obChar

End Sub
Reply With Quote