Solved

Count occurrances of word in MS Word 2010

Posted on 2011-02-20
3
333 Views
Last Modified: 2012-05-11
I am in the process of compiling a Test Report from my Test Procedures.  Need to count the number of "Pass" and "Fail" strings in a huge Word file.  All my relevant results are identified by a three asterik and then "Pass" or  "Fail" occurs.  Need quick way to compute total "Pass", "Fail", and both.
0
Comment
Question by:sdruss
3 Comments
 
LVL 4

Expert Comment

by:andreizz
ID: 34936221
0
 
LVL 59

Accepted Solution

by:
Chris Bottomley earned 500 total points
ID: 34936786
Depending on your version you can simply do an advanced find for the *** pass string and find all occurences then repeat for fail or perhaps a macro like below to do it for you.

Try the following macro which looks for *** Pass and *** fail.

If necessary modify to remove space or other formatting.

Chris
Sub passfail()
Dim intpass As Integer
Dim intfail As Integer
    
    ThisDocument.GoTo What:=wdGoToPage, Which:=wdGoToNext, Name:="1"
    With ThisDocument.Content.Find
        Do While .Execute(FindText:="*** pass", Forward:=True, Format:=True, _
           MatchWholeWord:=True, MatchCase:=False)
           intpass = intpass + 1
        Loop
    End With
    ThisDocument.GoTo What:=wdGoToPage, Which:=wdGoToNext, Name:="1"
    With ThisDocument.Content.Find
        Do While .Execute(FindText:="*** fail", Forward:=True, Format:=True, _
           MatchWholeWord:=True, MatchCase:=False)
           intfail = intfail + 1
        Loop
    End With
    MsgBox "Total ""Pass"" entries =  " & intpass & vbCrLf & _
    "Total ""Fail"" entries =  " & intfail & vbCrLf & _
    "Total entries =  " & intfail + intpass

End Sub

Open in new window

0
 
LVL 76

Expert Comment

by:GrahamSkan
ID: 34938682
It can't be used programatically, but you can do it quickly with a Find and Replace. Just have the same string for the Replace and for the Find part.

Find: ***Pass
Replace: ***Pass

The number of replacements is reported after the replacing is complete.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Word 2013/2016 Saving as Temp File 9 44
The blinking Office button 4 38
How to repeat a macro a certain number of times in Word 2010? 5 51
add more styles to my code 2 46
Introduction This tutorial provides instructions on how to properly format your Word document using the inbuilt tools provided. The benefits of using these tools means your documents are more accessible and easily portable to other applications an…
This is written from a 'VBA for MS Word' perspective, but I am sure it applies to most other MS Office components where VBA is used.  One thing that really bugs me is slow code, ESPECIALLY when it's mine!  In programming there are so many ways to…
This video walks the viewer through the process of creating a watermark for their document, customizing it, and saving it for viewing/printing needs.
Office 365 is currently available in five editions. Three of them are for business use: Office 365 Business Essentials, Office 365 Business, and Office 365 Business Premium. Two of them are for home/personal use: Office 365 Home and Office 365 Perso…

910 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now