Font.colorIndex vs Font.color

M

moonhkt

Hi All

Winword 2007

This is font.colorIndex and font.color ? Why font.color is -ve
Number ?

When character format as
Set Auto color colorindex is 0 , Font.color = -16777216
Set black color, colorindex is 7 , Font.color = -587137025
Set font color as red, colorindex is 0, font.colr = -721354753

below coding set X>Y XXXX format text with color font text values

Option Explicit
Rem
http://visualbasic.ittoolbox.com/gr...h-from-active-word-document-using-vba-2597342
Sub showPara()
Dim fndref As String
Dim par As Object
Dim i As Integer
'Dim par As Range
If ActiveDocument.Range.Paragraphs.Count > 0 Then

For Each par In ActiveDocument.Paragraphs
MsgBox par
Next par
End If

End Sub


Sub reportxx()
'~~ http://www.exceltip.com/st/Control_Excel_from_Word_using_VBA_in_Microsoft_Excel/463.html
'~~ Create Excel
'~~ Scan whole Word document
'~~ Append Excel record

Dim i As Integer
Dim aDoc As Document
Dim getStr As String
Dim ystr As String
Dim xcolor As Integer
Dim ln As Integer
Dim klist
Set aDoc = ActiveDocument
' MsgBox ActiveDocument.Name
Dim mywk As Excel.Workbook
Dim mysh As Excel.Worksheet
Set mywk = Excel.Workbooks.Add
Set mysh = mywk.Worksheets(1)

xcolor = 0
ln = 1
With mysh
.Cells(1, 1).Value = "Document"
.Cells(1, 2).Value = "Function/Description"
End With

For i = 1 To aDoc.Characters.Count
MsgBox "ColorIndex=" & aDoc.Range.Characters(i).Font.ColorIndex
& " Ch=" & aDoc.Range.Characters(i) & _
" " & aDoc.Range.Characters(i).Font.Color
'~~ http://msdn.microsoft.com/en-us/library/microsoft.office.interop.word.wdcolorindex.aspx
If aDoc.Range.Characters(i).Font.ColorIndex = wdAuto Or
aDoc.Range.Characters(i).Font.ColorIndex = wdBlack Then
xcolor = 0
Else
xcolor = 1
End If

If xcolor = 1 Then
If aDoc.Range.Characters(i) <> Chr(13) Then
If getStr = "" Then getStr = ActiveDocument.Name & "|"
getStr = getStr & aDoc.Range.Characters(i)
End If
Else
If InStr(getStr, ">") > 0 Then
If Trim(getStr) <> "" Then
ln = ln + 1
ystr = ystr & Trim(getStr) & Chr(13)

klist = Split(getStr, "|")
With mysh
.Cells(ln, 1) = klist(0)
.Cells(ln, 2) = klist(1)
End With
End If
End If
getStr = ""
End If
Next
'MsgBox ystr
mywk.Application.Visible = True
Set mywk = Nothing
Set mysh = Nothing
Set aDoc = Nothing
Set klist = Nothing
End Sub
 
S

Stefan Blom

ColorIndex and Color are simply different representations of colors.
ColorIndex can be used to set (and retrieve) a limited range of colors,
while the Color property probably represents an RGB color value.

For what it's worth, Color is hidden in Word 2010, meaning that it will be
removed from the Word object model in the future.

-- 
Stefan Blom
Microsoft Word MVP




---------------------------------------------
"moonhkt" wrote in message

Hi All

Winword 2007

This is font.colorIndex and font.color ? Why font.color is -ve
Number ?

When character format as
Set Auto color colorindex is 0 , Font.color = -16777216
Set black color, colorindex is 7 , Font.color = -587137025
Set font color as red, colorindex is 0, font.colr = -721354753

below coding set X>Y XXXX format text with color font text values

Option Explicit
Rem
http://visualbasic.ittoolbox.com/gr...h-from-active-word-document-using-vba-2597342
Sub showPara()
Dim fndref As String
Dim par As Object
Dim i As Integer
'Dim par As Range
If ActiveDocument.Range.Paragraphs.Count > 0 Then

For Each par In ActiveDocument.Paragraphs
MsgBox par
Next par
End If

End Sub


Sub reportxx()
'~~
http://www.exceltip.com/st/Control_Excel_from_Word_using_VBA_in_Microsoft_Excel/463.html
'~~ Create Excel
'~~ Scan whole Word document
'~~ Append Excel record

Dim i As Integer
Dim aDoc As Document
Dim getStr As String
Dim ystr As String
Dim xcolor As Integer
Dim ln As Integer
Dim klist
Set aDoc = ActiveDocument
' MsgBox ActiveDocument.Name
Dim mywk As Excel.Workbook
Dim mysh As Excel.Worksheet
Set mywk = Excel.Workbooks.Add
Set mysh = mywk.Worksheets(1)

xcolor = 0
ln = 1
With mysh
.Cells(1, 1).Value = "Document"
.Cells(1, 2).Value = "Function/Description"
End With

For i = 1 To aDoc.Characters.Count
MsgBox "ColorIndex=" & aDoc.Range.Characters(i).Font.ColorIndex
& " Ch=" & aDoc.Range.Characters(i) & _
" " & aDoc.Range.Characters(i).Font.Color
'~~
http://msdn.microsoft.com/en-us/library/microsoft.office.interop.word.wdcolorindex.aspx
If aDoc.Range.Characters(i).Font.ColorIndex = wdAuto Or
aDoc.Range.Characters(i).Font.ColorIndex = wdBlack Then
xcolor = 0
Else
xcolor = 1
End If

If xcolor = 1 Then
If aDoc.Range.Characters(i) <> Chr(13) Then
If getStr = "" Then getStr = ActiveDocument.Name & "|"
getStr = getStr & aDoc.Range.Characters(i)
End If
Else
If InStr(getStr, ">") > 0 Then
If Trim(getStr) <> "" Then
ln = ln + 1
ystr = ystr & Trim(getStr) & Chr(13)

klist = Split(getStr, "|")
With mysh
.Cells(ln, 1) = klist(0)
.Cells(ln, 2) = klist(1)
End With
End If
End If
getStr = ""
End If
Next
'MsgBox ystr
mywk.Application.Visible = True
Set mywk = Nothing
Set mysh = Nothing
Set aDoc = Nothing
Set klist = Nothing
End Sub
 
S

Stefan Blom

To clarify, the "limited range" I mentioned in my previous message is
defined by the wdColorIndex constants (look in the Object Browser of the
Visual Basic Editor).

-- 
Stefan Blom
Microsoft Word MVP




---------------------------------------------
"Stefan Blom" wrote in message
ColorIndex and Color are simply different representations of colors.
ColorIndex can be used to set (and retrieve) a limited range of colors,
while the Color property probably represents an RGB color value.

For what it's worth, Color is hidden in Word 2010, meaning that it will be
removed from the Word object model in the future.

-- 
Stefan Blom
Microsoft Word MVP




---------------------------------------------
"moonhkt" wrote in message

Hi All

Winword 2007

This is font.colorIndex and font.color ? Why font.color is -ve
Number ?

When character format as
Set Auto color colorindex is 0 , Font.color = -16777216
Set black color, colorindex is 7 , Font.color = -587137025
Set font color as red, colorindex is 0, font.colr = -721354753

below coding set X>Y XXXX format text with color font text values

Option Explicit
Rem
http://visualbasic.ittoolbox.com/gr...h-from-active-word-document-using-vba-2597342
Sub showPara()
Dim fndref As String
Dim par As Object
Dim i As Integer
'Dim par As Range
If ActiveDocument.Range.Paragraphs.Count > 0 Then

For Each par In ActiveDocument.Paragraphs
MsgBox par
Next par
End If

End Sub


Sub reportxx()
'~~
http://www.exceltip.com/st/Control_Excel_from_Word_using_VBA_in_Microsoft_Excel/463.html
'~~ Create Excel
'~~ Scan whole Word document
'~~ Append Excel record

Dim i As Integer
Dim aDoc As Document
Dim getStr As String
Dim ystr As String
Dim xcolor As Integer
Dim ln As Integer
Dim klist
Set aDoc = ActiveDocument
' MsgBox ActiveDocument.Name
Dim mywk As Excel.Workbook
Dim mysh As Excel.Worksheet
Set mywk = Excel.Workbooks.Add
Set mysh = mywk.Worksheets(1)

xcolor = 0
ln = 1
With mysh
.Cells(1, 1).Value = "Document"
.Cells(1, 2).Value = "Function/Description"
End With

For i = 1 To aDoc.Characters.Count
MsgBox "ColorIndex=" & aDoc.Range.Characters(i).Font.ColorIndex
& " Ch=" & aDoc.Range.Characters(i) & _
" " & aDoc.Range.Characters(i).Font.Color
'~~
http://msdn.microsoft.com/en-us/library/microsoft.office.interop.word.wdcolorindex.aspx
If aDoc.Range.Characters(i).Font.ColorIndex = wdAuto Or
aDoc.Range.Characters(i).Font.ColorIndex = wdBlack Then
xcolor = 0
Else
xcolor = 1
End If

If xcolor = 1 Then
If aDoc.Range.Characters(i) <> Chr(13) Then
If getStr = "" Then getStr = ActiveDocument.Name & "|"
getStr = getStr & aDoc.Range.Characters(i)
End If
Else
If InStr(getStr, ">") > 0 Then
If Trim(getStr) <> "" Then
ln = ln + 1
ystr = ystr & Trim(getStr) & Chr(13)

klist = Split(getStr, "|")
With mysh
.Cells(ln, 1) = klist(0)
.Cells(ln, 2) = klist(1)
End With
End If
End If
getStr = ""
End If
Next
'MsgBox ystr
mywk.Application.Visible = True
Set mywk = Nothing
Set mysh = Nothing
Set aDoc = Nothing
Set klist = Nothing
End Sub
 
M

moonhkt

To clarify, the "limited range" I mentioned in my previous message is
defined by the wdColorIndex constants (look in the Object Browser of the
Visual Basic Editor).

--
Stefan Blom
Microsoft Word MVP

---------------------------------------------

"Stefan Blom"  wrote in message
ColorIndex and Color are simply different representations of colors.
ColorIndex can be used to set (and retrieve) a limited range of colors,
while the Color property probably represents an RGB color value.

For what it's worth, Color is hidden in Word 2010, meaning that it will be
removed from the Word object model in the future.

--
Stefan Blom
Microsoft Word MVP

---------------------------------------------"moonhkt"  wrote in message


Hi All

Winword 2007

This is font.colorIndex and font.color ? Why font.color is -ve
Number ?

When character format as
Set Auto color colorindex is 0 , Font.color = -16777216
Set black color, colorindex is 7 , Font.color = -587137025
Set font color as red, colorindex is 0, font.colr = -721354753

below coding set X>Y XXXX format text with color font text values

Option Explicit
Remhttp://visualbasic.ittoolbox.com/groups/technical-functional/vb-vba-l....
Sub showPara()
Dim fndref As String
Dim par As Object
Dim i As Integer
'Dim par As Range
If ActiveDocument.Range.Paragraphs.Count > 0 Then

    For Each par In ActiveDocument.Paragraphs
        MsgBox par
    Next par
End If

End Sub

Sub reportxx()
'~~http://www.exceltip.com/st/Control_Excel_from_Word_using_VBA_in_Micro....
'~~ Create Excel
'~~ Scan whole Word document
'~~ Append Excel record

Dim i As Integer
    Dim aDoc As Document
    Dim getStr As String
    Dim ystr As String
    Dim xcolor As Integer
    Dim ln As Integer
    Dim klist
    Set aDoc = ActiveDocument
    ' MsgBox ActiveDocument.Name
    Dim mywk As Excel.Workbook
    Dim mysh As Excel.Worksheet
    Set mywk = Excel.Workbooks.Add
    Set mysh = mywk.Worksheets(1)

    xcolor = 0
    ln = 1
    With mysh
        .Cells(1, 1).Value = "Document"
        .Cells(1, 2).Value = "Function/Description"
    End With

    For i = 1 To aDoc.Characters.Count
      MsgBox "ColorIndex=" & aDoc.Range.Characters(i).Font.ColorIndex
& " Ch=" & aDoc.Range.Characters(i) & _
      " " & aDoc.Range.Characters(i).Font.Color
       '~~http://msdn.microsoft.com/en-us/library/microsoft.office.interop.word...
        If aDoc.Range.Characters(i).Font.ColorIndex = wdAuto Or
aDoc.Range.Characters(i).Font.ColorIndex = wdBlack Then
         xcolor = 0
        Else
         xcolor = 1
        End If

        If xcolor = 1 Then
         If aDoc.Range.Characters(i) <> Chr(13) Then
            If getStr = "" Then getStr = ActiveDocument.Name & "|"
            getStr = getStr & aDoc.Range.Characters(i)
          End If
        Else
            If InStr(getStr, ">") > 0 Then
                If Trim(getStr) <> "" Then
                    ln = ln + 1
                    ystr = ystr & Trim(getStr) & Chr(13)

                    klist = Split(getStr, "|")
                    With mysh
                        .Cells(ln, 1) = klist(0)
                        .Cells(ln, 2) = klist(1)
                    End With
                End If
            End If
            getStr = ""
        End If
    Next
    'MsgBox ystr
    mywk.Application.Visible = True
    Set mywk = Nothing
    Set mysh = Nothing
    Set aDoc = Nothing
    Set klist = Nothing
End Sub

Hi All

In my case, how to check the font is Auto color or set to other color
(red, green or other color) ?

Set Auto color colorindex is 0 , Font.color = -16777216
Set black color, colorindex is 7 , Font.color = -587137025
Set font color as red, colorindex is 0, font.colr = -721354753

I want extract color Text string. If text with auto color should be
ignored.

Moonhkt
 
S

Stefan Blom

Well, if the color is "Auto," ColorIndex equals zero, so that is easy.

But what color names are you referring to? One type is the named "standard"
colors already mentioned (= the WdColorIndex constants).

On the other hand, if you are referring to theme colors, make use of the
msoThemeColorIndex constants instead. Read about the OfficeTheme object in
Word VBA Help.

-- 
Stefan Blom
Microsoft Word MVP




---------------------------------------------
"moonhkt" wrote in message

To clarify, the "limited range" I mentioned in my previous message is
defined by the wdColorIndex constants (look in the Object Browser of the
Visual Basic Editor).

--
Stefan Blom
Microsoft Word MVP

---------------------------------------------

"Stefan Blom" wrote in message
ColorIndex and Color are simply different representations of colors.
ColorIndex can be used to set (and retrieve) a limited range of colors,
while the Color property probably represents an RGB color value.

For what it's worth, Color is hidden in Word 2010, meaning that it will be
removed from the Word object model in the future.

--
Stefan Blom
Microsoft Word MVP

---------------------------------------------"moonhkt" wrote in message


Hi All

Winword 2007

This is font.colorIndex and font.color ? Why font.color is -ve
Number ?

When character format as
Set Auto color colorindex is 0 , Font.color = -16777216
Set black color, colorindex is 7 , Font.color = -587137025
Set font color as red, colorindex is 0, font.colr = -721354753

below coding set X>Y XXXX format text with color font text values

Option Explicit
Remhttp://visualbasic.ittoolbox.com/groups/technical-functional/vb-vba-l...
Sub showPara()
Dim fndref As String
Dim par As Object
Dim i As Integer
'Dim par As Range
If ActiveDocument.Range.Paragraphs.Count > 0 Then

For Each par In ActiveDocument.Paragraphs
MsgBox par
Next par
End If

End Sub

Sub reportxx()
'~~http://www.exceltip.com/st/Control_Excel_from_Word_using_VBA_in_Micro...
'~~ Create Excel
'~~ Scan whole Word document
'~~ Append Excel record

Dim i As Integer
Dim aDoc As Document
Dim getStr As String
Dim ystr As String
Dim xcolor As Integer
Dim ln As Integer
Dim klist
Set aDoc = ActiveDocument
' MsgBox ActiveDocument.Name
Dim mywk As Excel.Workbook
Dim mysh As Excel.Worksheet
Set mywk = Excel.Workbooks.Add
Set mysh = mywk.Worksheets(1)

xcolor = 0
ln = 1
With mysh
.Cells(1, 1).Value = "Document"
.Cells(1, 2).Value = "Function/Description"
End With

For i = 1 To aDoc.Characters.Count
MsgBox "ColorIndex=" & aDoc.Range.Characters(i).Font.ColorIndex
& " Ch=" & aDoc.Range.Characters(i) & _
" " & aDoc.Range.Characters(i).Font.Color

'~~http://msdn.microsoft.com/en-us/library/microsoft.office.interop.word...
If aDoc.Range.Characters(i).Font.ColorIndex = wdAuto Or
aDoc.Range.Characters(i).Font.ColorIndex = wdBlack Then
xcolor = 0
Else
xcolor = 1
End If

If xcolor = 1 Then
If aDoc.Range.Characters(i) <> Chr(13) Then
If getStr = "" Then getStr = ActiveDocument.Name & "|"
getStr = getStr & aDoc.Range.Characters(i)
End If
Else
If InStr(getStr, ">") > 0 Then
If Trim(getStr) <> "" Then
ln = ln + 1
ystr = ystr & Trim(getStr) & Chr(13)

klist = Split(getStr, "|")
With mysh
.Cells(ln, 1) = klist(0)
.Cells(ln, 2) = klist(1)
End With
End If
End If
getStr = ""
End If
Next
'MsgBox ystr
mywk.Application.Visible = True
Set mywk = Nothing
Set mysh = Nothing
Set aDoc = Nothing
Set klist = Nothing
End Sub

Hi All

In my case, how to check the font is Auto color or set to other color
(red, green or other color) ?

Set Auto color colorindex is 0 , Font.color = -16777216
Set black color, colorindex is 7 , Font.color = -587137025
Set font color as red, colorindex is 0, font.colr = -721354753

I want extract color Text string. If text with auto color should be
ignored.

Moonhkt
 

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. After that, you can post your question and our members will help you out.

Ask a Question

Top