Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 01-06-2013, 05:01 PM
Jennifer Murphy's Avatar
Jennifer Murphy Jennifer Murphy is offline Testing for a printable character Windows XP Testing for a printable character Office 2007
Competent Performer
Testing for a printable character
 
Join Date: Aug 2011
Location: Silicon Valley
Posts: 234
Jennifer Murphy is on a distinguished road
Default Testing for a printable character


Is there a good way to test whether a character is one that would be displayed on screen and printed?

I'm working on a little macro to change each character in a string of text to a random color according to some theme. For the Christmas theme, each letter would be changed to red or green. For Halloween, orange or black.

The macro limits the number of consecutive characters that can be assigned the same color. The problem is that non-printing characters, like space and tab, defeat the limit.

If I set the limit to 3, then the macro will not allow more than three consecutive characters to be assigned the same color. But it will happily allow three characters on either side of a space to all be red as long as the space is green. But since the space is non-printing, it looks like there are 6 red characters.
Reply With Quote
  #2  
Old 01-09-2013, 06:17 AM
gmaxey gmaxey is offline Testing for a printable character Windows 7 32bit Testing for a printable character Office 2010 (Version 14.0)
Expert
 
Join Date: May 2010
Location: Brasstown, NC
Posts: 1,598
gmaxey is just really nicegmaxey is just really nicegmaxey is just really nicegmaxey is just really nicegmaxey is just really nice
Default

Code:
Sub ScratchMacro()
'A basic Word macro coded by Greg Maxey
Dim oChar As Range
For Each oChar In Selection.Range.Characters
  Debug.Print Asc(oChar) 'For information.  Remove in final code.
  Select Case Asc(oChar)
    Case 65 To 90, 97 To 122, 48 To 57 'AZaz0-9
      oChar.Font.Color = wdColorRed
    Case 9, 10, 11, 13, 32, 160
      'Skip
    Case Else
      '????
  End Select
Next oChar
End Sub
__________________
Greg Maxey
Please visit my web site at http://www.gregmaxey.com/
Reply With Quote
  #3  
Old 01-09-2013, 06:42 PM
Jennifer Murphy's Avatar
Jennifer Murphy Jennifer Murphy is offline Testing for a printable character Windows XP Testing for a printable character Office 2007
Competent Performer
Testing for a printable character
 
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
Reply



Similar Threads
Thread Thread Starter Forum Replies Last Post
Printable Area issues zaineyma Word 3 12-12-2012 09:11 AM
Testing for a printable character HELP/ADVICE NEEDED. Testing Excel Accessibility guidelines cmc89 Excel 1 03-29-2012 03:41 PM
Printable Entry Form eJames Excel 1 01-07-2010 09:50 AM
Making template that is not printable Askaleto Word 0 10-14-2009 11:45 AM
Defining Printable Areas OfficeUser00939 Word 5 06-29-2009 09:04 AM

Other Forums: Access Forums

All times are GMT -7. The time now is 09:19 AM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2025, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2025 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft