Wednesday, February 10, 2010

Using Macros to find specific word occurrences

Recently I found two useful macros that count word occurrences. I had been wondering how many times I used a specific word in my story, then realized there was no way in Word to check this. Installing these two macros was fast and easy (once, I figured out how to install macros on Word ;) ) and they create interesting reports on word occurrences in your document.

I've been playing around with both macros to much amusement. It's handy for writing; for example, I've checked to see how many times I've used certain adverbs, ones I definitely want to cut down on, like "loudly" or "softly." If the number is high, I know it's something I need to work on in editing. Using the macros, along with something like AutoCrit provides a good "map" of one's writing and gives a good indication of things that need to be changed or worked on in the editing phase.

For those who, like me, had never tinkered with macros in Word, here's a quick tutorial on how to get these word occurrence macros up and working:


  • Step One:


  • Open up the macros menu.

    In Office Word 2007, it's located under the "View" tab, at the end. In an older version of Office Word, the macro button should be located under the "Tools" menu.

  • Step Two:


  • Once you have opened the menu, choose a name for the macros that match the names given on this page; in other words, the first one will be called FindWords and the second one will be called WordFrequency. Let's start with the first one. Type in FindWords as the macro name:

    macro1

  • Step Three:


  • Once you type in the name, click "Create" and a new window in Microsoft Visual Basic should open up, allowing you to copy and paste your macro into a window. You can get the code from WordTips.net. It will be the first set of code that starts with Sub FindWords().

    Highlight whatever text is already there. We don't need it, so we're going to copy and paste over it. Copy and paste the whole code into the Visual Basic window. In the end, it should look like this:

    [caption id="attachment_170" align="aligncenter" width="300" caption="Click on the picture for a full view"]macro3[/caption]

    Once you have finished copy and pasting, go to File and choose Save Normal. Then close out of the window by clicking on the "X" at the right-hand corner. You'll be back at your Word document.

    Test out the new macro! Go back to the macros window (where you typed in the name of the macro). Highlight FindWords from the menu and click "Run." Let the macro do its work! It will take longer to count the word occurrence dependent on how many words and pages your document is.

    macro4

    macro5

    Neat, huh? :) But say that you want to find how many times certain words appear in your document? Say you want to find out how many times you use the word "there" versus "their"? You can create a macro that does this too, and it's located on the same page.

  • Step One:


  • Just like before, create a new macro. This time, we will call the macro WordFrequency. In the Microsoft Visual Basic editor, copy and paste the second code from the WordTips.net website; it starts with Sub WordFrequency()

  • Step Two:


  • Again, highlight over whatever text is there (it should start with Sub WordFrequency() just like before) as the code will be copied and pasted over it.

    You'll notice that you can see the end of your previous macro (in my cast, it was the end of FindWords, which I'd just created). Don't mess with the code! Make sure you do all your copy and pasting below the line that signifies the end of the previous macro (take a peek at the image below).

    [caption id="attachment_176" align="aligncenter" width="300" caption="Click on the image to see the full view"]macro6[/caption]

    Once the code is copied and pasted, save it by going to "File" and "Save Normal", then exit out of the editor by clicking on the "X" button at the right-hand corner (just like before). And you're done! :)

    Test out the macro! Go back to the macro menu, choose WordFrequency from the list, and click "Run," then choose if you want it to count by word or frequency. This macro does take a bit of time, after all it's counting how many instances there are of each word in your document. Be patient, you'll know it's done when a new, untitled word document pops up.

    1 comment:

    1. Good post and this mail helped me alot in my college assignement. Say thank you you as your information.

      ReplyDelete

    What do you think? Got something to say? Type away!