none
Find color of charater in Word using VB RRS feed

  • Question

  • Hello,

    I can open a Word file and look at each character using this code. ]I can get the Ascii equivolent for each character.

     

    For i = 1 To count

    char1 = oDoc.Characters(i).Text

    Now I need to find a color in the text. The text is of different colors. I need to be able to detect the color as each character is looked at.

     


    Mario
    • Moved by Kee Poppy Monday, January 9, 2012 6:32 AM (From:Visual Basic Express Edition)
    Friday, January 6, 2012 6:38 PM

Answers

  • You'll want to use the value from ".Font.ColorIndex" of the character.
    Kind Regards, Rich ... http://greatcirclelearning.com
    Monday, January 9, 2012 12:22 PM

All replies

  • I'm not familiar with the object model for Word documents, but does Characters(i) have a Font property? If so, Does Font have a Color property? Something like:

    myColour = oDoc.Characters(i).Font.Color

    If that doesn't work, you might want to try the Object browser on Word's VBA IDE. Even though you are using VB.Net rather than VBA, Word's Object browser is probably the best way to find out what properties and methods exist in the Word object model.



    Friday, January 6, 2012 7:19 PM
  • Hi Mario,

    In case of you need, I will move this thread to Word for Developers forum for more responses.

    Have a nice day,


    Kee Poppy [MSFT]
    MSDN Community Support | Feedback to us
    Monday, January 9, 2012 6:32 AM
  • You'll want to use the value from ".Font.ColorIndex" of the character.
    Kind Regards, Rich ... http://greatcirclelearning.com
    Monday, January 9, 2012 12:22 PM
  • This does not really work cause I could never get font.color into a variable

    The way I was shown was to use a range.font.colorindex which with a little tinkering finally did work. Thank you anyway


    Mario
    Tuesday, January 10, 2012 6:00 PM
  • This worksbetter I still had to use a range.font.colorindex, but it works so thanks a lot
    Mario
    Tuesday, January 10, 2012 6:06 PM
  • You don't say what version of Word you are using, but the ColorIndex property is limited in old versions, and plain wrong in 2007 and later. What problem did you have using .Color?
     
    ------=_NextPart_000_0E2B_01CCD618.469DFD20
    Content-Type: text/html;
    charset="utf-8"
    Content-Transfer-Encoding: quoted-printable
     
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
    <HTML><HEAD>
    <META content="text/html; charset=utf-8" http-equiv=Content-Type>
    <META name=GENERATOR content="MSHTML 8.00.6001.18702">
    <STYLE></STYLE>
    </HEAD>
    <BODY bgColor=#ffffff>
    You don't say what version of Word you are using,
    but the ColorIndex property is limited in old versions, and plain wrong in 2007
    and later. What problem did you have using .Color?
     
    </BODY></HTML>
     
     

    Enjoy,
    Tony
    www.WordArticles.com
    Wednesday, January 18, 2012 7:34 PM