Changing the highlighted color of a character

Discussion in 'Word Programming' started by jic, Nov 20, 2013.

  1. jic

    jic Guest

    Greetings.

    I have a Word document that has highlighted characters. I would like to "unhighlight" certain charcters based on their character codes (charCodeAt()).. I have created this JScript script,

    /////////////////////////START//////////////////////////
    var w = WScript;
    var file = "c:\\temp\\test.doc";
    var word;
    var desiredColor = 7;
    try
    {
    word = GetObject("","Word.Application");
    }
    catch(e)
    {
    word = w.CreateObject("Word.Application");
    }
    var doc = word.Documents.Open(file);
    var myRange = doc.Range(0,0);
    var chars = 1;
    w.Echo("Total Characters grabbed is " + myRange.Characters.Count);
    while (chars <= myRange.Characters.Count)
    {
    w.Echo(myRange.Characters(chars).Text.charCodeAt(0));
    if (myRange.Characters(chars).Text.charCodeAt(0) == 12)
    {
    w.Echo("Color for code 12 is " + myRange.Characters.Parent.HighlightColorIndex);
    if (myRange.Characters(chars).Parent.HighlightColorIndex == desiredColor ||
    myRange.Characters(chars).Parent.HighlightColorIndex == 9999999)
    {
    myRange.Characters(chars).Parent.HighlightColorIndex = 0;
    }
    }
    chars++;
    }
    /////////////////////////END//////////////////////////

    But, somehow it is only getting one character. Any help would be greatly appreciated. Thanks.

    josé
     
    jic, Nov 20, 2013
    #1
    1. Advertisements

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. yonido

    Change line color

    yonido, Oct 7, 2003, in forum: Word Programming
    Replies:
    3
    Views:
    161
    Mick Hardy
    Oct 16, 2003
  2. Replies:
    0
    Views:
    97
  3. Jared L

    Range location versus character count

    Jared L, Jun 19, 2006, in forum: Word Programming
    Replies:
    3
    Views:
    109
    Jezebel
    Jun 20, 2006
  4. VinceB1 via OfficeKB.com

    Wildcard character syntax

    VinceB1 via OfficeKB.com, Sep 25, 2006, in forum: Word Programming
    Replies:
    1
    Views:
    80
    Jezebel
    Sep 25, 2006
  5. Replies:
    4
    Views:
    120
    Jean-Guy Marcil
    Nov 7, 2006
  6. Mark246
    Replies:
    3
    Views:
    139
    Perry
    May 15, 2007
  7. PZ
    Replies:
    0
    Views:
    181
  8. John Smith

    escape character, ", smart quote

    John Smith, Oct 19, 2010, in forum: Word Programming
    Replies:
    2
    Views:
    238
    John Smith
    Oct 21, 2010
Loading...