Count the number of bold entries

M

Michael Singmin

Hello Group,

I have a document of 200 single words, each on a different line.
Some of them are Bold.

What is the VBA code to count those bold entries ?
I would like a construct like this pseudo code

For each fs in Document
If Fs = Bold then Count = Coumt +1
Next

In Excel, the Worksheet or Sheet is the common page.
What is the equivalent in Word ?

Thanks,

Michael Singmin
 
G

Greg Maxey

Michael,

If each single word entry is on separate line I will assume that each word
is an individual paragraph. Something like this might work:

Sub Test()
Dim i As Long, pararange As Range
Dim j As Long
j = 0
For i = 1 To ActiveDocument.Paragraphs.Count
Set pararange = ActiveDocument.Paragraphs(i).Range
If pararange.Font.Bold = True Then j = j + 1
Next i
MsgBox "There are " & j & " bolded entries in this document"
End Sub
 
M

Michael Singmin

Thank you Greg,

Your code was most instructive.

Michael
====================================================
 

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