Solved

WORD - Word Count

Posted on 2011-03-11
5
401 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
  • 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 31

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 500 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

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

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 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…
The viewer will learn how to make their project stand out over others by learning how to change colors and shapes, add spaces, change directions, and add bullets to their charts.
This video shows where to find the word count, how to display it, and what it breaks down to in Microsoft Word.

762 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

22 Experts available now in Live!

Get 1:1 Help Now