Home | Tips | Library | Other Authors | Other WP Sites | Writer's Links | Contact | Site Map | Donate

Barry MacDonnell's
Toolbox for WordPerfect

Macros, tips, and templates for Corel® WordPerfect® for Windows®
© Copyright 1996-2019 by Barry MacDonnell. All Rights Reserved.

Page updated Feb 11, 2019

COUNTTXT - Count specific words or other text strings

Download COUNTTXT.ZIP (v1.02; 03/06/2013; 7,447 bytes)

Compatible with WordPerfect 8 and later versions

Downloading, Documentation, Modifications, and Support

CountTxt.wcm - A macro that searches for and counts specific words or phrases in the document -- e.g., the number of times your client's name appears.

This is another example of how to count text items using a search routine with a "loop-and-increment-counter".

Notes and limitations 

The macro language limits macro variable storage to 79 characters, including spaces. (See here for more.) This is the limit you can enter in the macro's pop up menu.

Hyphenated words (with [-Hyphen] codes) will not be found or counted.

Tip

You can also search for, and get a count of, a specific word using WordPerfect's own search feature:

Place the cursor where you want to begin searching (usually at the very top of the document).

[1] Click on Edit, Find and Replace.

[2] Enter the word you want to count in the Find field.

[3] Enter the exact same word in the Replace field.

[4] If you want to search inside headers, footers, and other substructures, enable that option in the F&R dialog's menu (under Options).

[5] Then click Replace All.

WordPerfect will then give you a count of the replacements. (Of course, this method modifies your document, but you can always close it without saving it. Or you should be able to use Edit, Undo to restore it.)

Other related macros

•  To count ALL individual words in a selection of text or in the entire document see the WordList macro, which has two functions:

[A] The WordList macro can create a word frequency (i.e., word count) list,

   or

[B] it can create an alphabetical list of all words used at least once (which can help create a concordance file to help with indexing the document).

The first option will separately list ALL words and their individual frequencies (i.e., word counts) in the current document.

The list is created in a separate document so that processing will not impact your current document.

•  The TooClose macro examines your document for duplicate words that are "too close" together according to a user-defined proximity setting.

•  To count ALL words and other text items in "real time" as you type or edit a document, see Footnote 1 for a macro that uses WordPerfect's built-in text count feature.

Footnote 1

[Note that this macro was written in WPX6/WPX7, so it might not work in earlier versions of WordPerfect.]

The following macro displays a real-time (i.e., dynamically updated) count of various text items in the document (characters, words, sentences, paragraphs, lines and pages).

The dialog can be dragged into another position and remains on screen until you dismiss it. Hence you can type into the document while using it. You can even switch to another document while the dialog is on screen and it will show the
new document's information.

To copy this code into your WordPerfect program to create a working macro, see http://wptoolbox.com/tips/CopyCode.html.

Once you save the macro you can assign it to a toolbar, shortcut key, or menu to make it quick and easy to play -- see http://wptoolbox.com/tips/EasyPlay.html.

[Small vaveat about line counts: Note that it uses WordPerfect's built-in text count feature (File, Properties, Word Count (tab)), so line counts might differ from the Line Counter macro in the main Library.]

// Purpose:
// Displays a (draggable) dialog on screen with the number of words and pages in the document.
// You can even switch to another document while the dialog is on screen and it will show the
// new document's information.
// When you are done with it just click on the dialog's "X" or press the Esc key.
//
OnCancel(QuitNow@)
Display(On!)
InhibitInput(Off!)
vHRt:=NToC(0F90Ah)  // (adds a hard return)
While(True)
    Prompt
    ("Count Text Items in Current Document";
    "Characters: "+DocumentInfo(Characters!) +vHRt+vHRt+
    "Words: "+DocumentInfo(Words!) +vHRt+vHRt+
    "Sentences: "+DocumentInfo(Sentences!) +vHRt+vHRt+
    "Paragraphs: "+DocumentInfo(Paragraphs!)  +vHRt+vHRt+ 
    "Lines: "+DocumentInfo(Lines!)  +vHRt+vHRt+ 
    "Pages: "+DocumentInfo(Pages!)  +vHRt+vHRt+
    "- Click in document to TYPE or NAVIGATE."+vHRt+
    "- You can DRAG this dialog to another screen location."+vHRt+
    "- Click on this dialog's 'X' -or- press ESC key to quit."+vHRt+
    "[Data is from WordPerfect's built-in File>Properties>Word Count feature."+vHRt+
    "See macro help for items that can be included.]";
    NoIcon! | NoPause! | NoButtons! ;
    )
    Wait(5)  // (pause loop for 0.5 seconds)
Endwhile
Label(QuitNow@)
Quit