Solved

Count occurrances of word in MS Word 2010

Posted on 2011-02-20
3
338 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

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

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

Like many others, we try and discourage users from printing documents unnecessarily and instead send or share them electronically. However, this doesn't always work and documents are still printed. With this simple solution, if the user tries to …
Introduction Authors who set out to write any sort of lengthy piece for online submission—be it a long question or comment on a technical form, an article, or a substantial blog entry—often find it useful to work up a draft in an editor other t…
This video teaches the viewer how to align pictures around text while keeping the text properly aligned in the document.
This video shows where to find templates, what they are used for, and how to create and save a custom template using Microsoft Word.

810 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