Solved

WORD - Word Count

Posted on 2011-03-11
5
406 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 32

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

[Webinar] How Hackers Steal Your Credentials

Do You Know How Hackers Steal Your Credentials? Join us and Skyport Systems to learn how hackers steal your credentials and why Active Directory must be secure to stop them. Thursday, July 13, 2017 10:00 A.M. PDT

Question has a verified solution.

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

I would like to show you some basics you can do with Mailings in MS Word. It´s quite handy feature you can use for creating envelopes, labels, personalized letters etc. First question could be what is this feature good for? Mailing can really he…
Shortcuts in Word Just the other day I had a training for Microsoft and they wanted me to show how well the new Windows and Office behaved on a touch device, which by the way is great, but it was only then that I realized that using keyboard shortc…
This video shows where to find templates, what they are used for, and how to create and save a custom template using Microsoft Word.
Office 365 is currently available in five editions. Three of them are for business use: Office 365 Business Essentials, Office 365 Business, and Office 365 Business Premium. Two of them are for home/personal use: Office 365 Home and Office 365 Perso…

688 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