Results 1 to 3 of 3
  1. #1
    New Lounger
    Join Date
    May 2009
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Hi there - just found this forum and looks like some great VBA experts. I have tried searching through google with different criteria to try and figure out how to do this using Word or Photoshop but can't find it.

    Basically I want to select some text and then cycle through each character and set the first character as blue, the second as red and the third as yellow and continue until end of selection. The colors in question are -553582593, -721354753 and wdColorGold. It should disregard the white space so if the text was

    Test This then would be T(Blue) e(Red) s(Yellow) t(Blue) space(Ignore) T(Red) i(Yellow) s(Blue)

    I was looking at using a pRange then looping through using the code by using With Selection and the .MoveRight and select then change color but can't quite figure it out

    Any help much appreciated

    Paul

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts
    Welcome to the Lounge!

    How should the code treat interpunction (periods, commas, ...)?
    How should it treat digits (0...9)?
    How should it treat line breaks and paragraph breaks?

  3. #3
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts
    Here is a primitive attempt. The negative color values caused errors, so I replaced them with wdColorBlue and wdColorRed.

    This version will not color line and paragraph breaks, tabs and spaces, but it will color interpunction and digits:

    Code:
    Sub ColorChars()
      Dim n As Long
      Dim c As Integer
      Dim arrColors(0 To 2) As Long
      arrColors(0) = wdColorBlue
      arrColors(1) = wdColorRed
      arrColors(2) = wdColorGold
      For n = 1 To Len(Selection)
    	If Asc(Selection.Characters(n)) > 32 Then
    	  Selection.Characters(n).Font.Color = arrColors(c)
    	  c = (c + 1) Mod 3
    	End If
      Next n
    End Sub
    If you want to exclude digits and some interpunction, change 32 to 64.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •