Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

WORD - Word Count

Posted on 2011-03-11
5
Medium Priority
?
410 Views
Last Modified: 2012-06-27
Hi,

Is there a way in WORD to set a formula where every time a specific word appears, a sequential counter can be added before or after this word?

Thanks
0
Comment
Question by:tahirih
[X]
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
  • 2
  • 2
5 Comments
 
LVL 76

Expert Comment

by:GrahamSkan
ID: 35113363
It would need to be done programatically after the document is complete. This VBA macro would do it.
Sub WordNumber()
    Dim i As Long
    Dim rng As Range
    
    Set rng = ActiveDocument.Range
    With rng.Find
        .Wrap = wdFindStop
        .MatchWildcards = True
        .Text = "<myword>"
        Do While .Execute
            i = i + 1
            rng.Collapse wdCollapseEnd
            rng.Text = " " & i
            rng.End = ActiveDocument.Range.End
        Loop
    End With
End Sub

Open in new window

0
 
LVL 33

Expert Comment

by:Paul Sauvé
ID: 35113766
Hi t.,

When i want to find the number of times a specific word appears in a Word document, I simply replace the word with the same word and Word tells me how many of the word it changed.
 
It is much quicker to do than to write the explanation.

P. WORD - Word Count
0
 

Author Comment

by:tahirih
ID: 35115992
Let me please clarify - what is requested is not a total word count - but to actually number the words in the document.

i.e.

Word, Word, Word

would become

Word1, Word2, Word3

Thank you
0
 
LVL 76

Accepted Solution

by:
GrahamSkan earned 2000 total points
ID: 35116111
Here is a rewritten macro. This uses 'Word' as an example instead of 'myword', and doesn't put a space before the number.
Sub WordNumber()
    Dim i As Long
    Dim rng As Range
    
    Set rng = ActiveDocument.Range
    With rng.Find
        .Wrap = wdFindStop
        .MatchWildcards = True
        .Text = "<Word>"
        Do While .Execute
            i = i + 1
            rng.Collapse wdCollapseEnd
            rng.Text = i
            rng.End = ActiveDocument.Range.End
        Loop
    End With
End Sub

Open in new window

0
 

Author Closing Comment

by:tahirih
ID: 35148699
Thank you.
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone 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

The Selection object is designed for user interaction. It has a Range property, so it can be used in most places that a Range object can. Recorded macros must use the Selection because they are simply copying what the user is doing. A Range prope…
Using Word 2013, I was experiencing some incredible lag when typing.  Here's what worked for me....
In this video, we show how to convert an image-only PDF file into a PDF Searchable Image file, that is, a file with both the image (typically from scanning) and text, which is created in an automated fashion with Optical Character Recognition (OCR) …
This video walks the viewer through the process of creating an MLA formatted document, as well as a bibliography with citations.

604 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