Counting words in a specific color

J

John Doue

That must be basic for some of you but I need to count words in a
document which are in a specific color. A detailed report itemizing the
number of words for each color appearing in a document would be ideal.

Thanks for any help.

Regards
 
H

Helmut Weber

Hi John,

what color?

How was the color applied?
By highlighting, or by setting the color of the font,
or by setting the background color?

Basic sample for font color.

Dim rDcm As Range
Dim l As Long
Set rDcm = ActiveDocument.Range
With rDcm.Find
.Font.Color = wdColorRed
' could be .Font.Color = 16331580
While .Execute
l = l + 1
' or do something else with was found
Wend
End With
MsgBox l

There were l uninterrupted sequences
of wdColorRed found. Not words!

That is a different matter.

--
Greetings from Bavaria, Germany

Helmut Weber, MVP WordVBA

Win XP, Office 2003
"red.sys" & Chr$(64) & "t-online.de"
 
J

John Doue

Helmut said:
Hi John,

what color?

How was the color applied?
By highlighting, or by setting the color of the font,
or by setting the background color?

Basic sample for font color.

Dim rDcm As Range
Dim l As Long
Set rDcm = ActiveDocument.Range
With rDcm.Find
.Font.Color = wdColorRed
' could be .Font.Color = 16331580
While .Execute
l = l + 1
' or do something else with was found
Wend
End With
MsgBox l

There were l uninterrupted sequences
of wdColorRed found. Not words!

That is a different matter.
Thanks Helmut.

The problem is, I receive the document and cannot know how the color was
applied. I am assuming it was by selecting a font color. I am not sure I
understand your code "1 = 1 + 1" Assuming I want to delete the
corresponding colored text, how should this read?

Thanks again for your patience
 
H

Helmut Weber

Hi John,

due to being a lazy typer,
I should have named the variable lCnt,
long counter. It's "l", ot "1".

For deleting all text of a specific color,
you first have to know the color.

MsgBox selection.Font.Color

If the originators of the doc
have played around with colors,
you are at a loss.

--
Greetings from Bavaria, Germany

Helmut Weber, MVP WordVBA

Win XP, Office 2003
"red.sys" & Chr$(64) & "t-online.de"
 

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