Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

Count occurrances of word in MS Word 2010

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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Free Online PDF Converter 2 66
CheckBox Not Recognized as True When Checked 3 36
Office 365 home questions 7 77
Problem with MS Word 12 30
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…
Learn how to make your own table of contents in Microsoft Word using paragraph styles and the automatic table of contents tool. We'll be using the paragraph styles in Word’s Home toolbar to help you create a table of contents. Type out your initial …
This Micro Tutorial well show you how to find and replace special characters in Microsoft Word. This is similar to carriage returns to convert columns of values from Microsoft Excel into comma separated lists.

809 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