Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Word / Programming / November 2004

Tip: Looking for answers? Try searching our database.

Count the number of bold entries

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Michael Singmin - 26 Nov 2004 21:40 GMT
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
Greg Maxey - 26 Nov 2004 21:50 GMT
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

Signature

Greg Maxey/Word MVP
A Peer in Peer to Peer Support

> Hello Group,
>
[quoted text clipped - 14 lines]
>
> Michael Singmin
Michael Singmin - 28 Nov 2004 13:13 GMT
Thank you Greg,

Your code was most instructive.

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

"Greg Maxey" <gro.spvm@yexamg (thats my e-mail address backwards)>
wrote:

>Michael,
>
[quoted text clipped - 11 lines]
>MsgBox "There are " & j & " bolded entries in this document"
>End Sub
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.