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
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