Tuesday, January 31, 2012

This one is a public service announcement. A little light on the entertainment value. Sorry.
So here's the deal: sometimes you're writing a document that has specific word count requirements for various sections. I run into this all the time writing manuscripts. Various journals will have word limits for different sections: an abstract of no more than 250 words, an introduction of no more than 1500 words, and so on. As you type, Microsoft Word gives you the total word count for your document, so you only have an idea about whether the first section of your document fits within the allotted word count. The kludgy workaround is to copy and paste each section into a new document, which will give you the total word count for that section. Annoying. Even more annoying if you were over-budget, and have to make repeated edits and checks until you come in under the limit. Wouldn't it be great if you could get a section-by-section word count breakdown? You can. I wrote a macro to do just this. To begin, you have to make use of section breaks, which are nothing more than a means to group different sections of text together. You can insert them between any chunks of text you would like, according to your needs. Once you've done this, you can get the word count for each section with this macro:

Sub SectionWordCount()

    Dim NumSec As Integer
    Dim S As Integer
    Dim Summary As String

    NumSec = ActiveDocument.Sections.Count
    Summary = "Word Count" & vbCrLf


    For S = 1 To NumSec
        Summary = Summary & "Section " & S & ": " _
          & ActiveDocument.Sections(S).Range.ComputeStatistics(wdStatisticWords) _
          & vbCrLf
    Next

    Summary = Summary & "Document: " & _
      ActiveDocument.Range.ComputeStatistics(wdStatisticWords)
    MsgBox Summary
End Sub

Create a new macro in MS Word, copy and paste this code into the VB Editor and you're good to go.

I don't think this one will be nearly as popular as my Catan series.

0 comments: