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

Ask a Question

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.