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?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.
Similar Threads
  1. yonido

    Change line color

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

    Range location versus character count

    Jared L, Jun 19, 2006, in forum: Word Programming
    Replies:
    3
    Views:
    122
    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:
    92
    Jezebel
    Sep 25, 2006
  5. Replies:
    4
    Views:
    134
    Jean-Guy Marcil
    Nov 7, 2006
  6. Mark246
    Replies:
    3
    Views:
    152
    Perry
    May 15, 2007
  7. PZ
    Replies:
    0
    Views:
    195
  8. John Smith

    escape character, ", smart quote

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