• Word Count Macro (Word 2000 )

    Author
    Topic
    #364543

    I need to write a word count macro that has to count words in a document that includes endnotes and footnotes. I have the following:

    “Sub startrun()
    Button = MsgBox(“Select the portion of the Document that should be included in the Word Count.” + Chr(13) + “Court rules vary, please make sure your selection complies with applicable court rules”, 1, “Text Selection”)
    continue
    End Sub

    Sub WordCount()
    ‘If cursor is in footnotes or endnotes, cancel macro
    Dim StoryTypeStr As String
    On Error GoTo Wordcount_error

    Select Case Selection.StoryType
    Case wdCommentsStory
    StoryTypeStr = “a comment”
    Case wdEndnotesStory
    StoryTypeStr = “an endnote”
    Case wdEvenPagesFooterStory
    StoryTypeStr = “a footer”
    Case wdEvenPagesHeaderStory
    StoryTypeStr = “a header”
    Case wdFirstPageFooterStory
    StoryTypeStr = “a footer”
    Case wdFirstPageHeaderStory
    StoryTypeStr = “a header”
    Case wdFootnotesStory
    StoryTypeStr = “a footnote”
    Case wdMainTextStory
    StoryTypeStr = “the main body”
    Case wdPrimaryFooterStory
    StoryTypeStr = “a footer”
    Case wdPrimaryHeaderStory
    StoryTypeStr = “a header”
    Case wdTextFrameStory
    StoryTypeStr = “a text box”
    End Select

    If Selection.StoryType wdMainTextStory Then
    MsgBox “Before you can run a Word Count, your cursor must be in the main body of the document.” & _
    vbCrLf & vbCrLf & “Right now, your cursor is in ” & StoryTypeStr & “.”
    Exit Sub

    Exit Sub
    End If

    Load FrmWordCount
    FrmWordCount.Show

    Wordcount_error:
    End Sub

    Public Sub continue()
    ‘Application.Run MacroName:=”WordCount”‘
    With CommandBars(“Continue”)
    .Visible = True
    .Top = 200
    End With
    End Sub”
    Problems
    1 The cancel button in the message box does not work
    2. If text already selected I need the macro to not prompt but just run
    Any ideas

    Viewing 1 reply thread
    Author
    Replies
    • #559982

      Hi,

      You could try the following:

      Sub startrun()
      If Selection.Type wdNoSelection Then
      Button = MsgBox(“Select the portion of the Document that should be included in the Word Count.” + Chr(13) + “Court rules vary, please make sure your selection complies with applicable court rules”, 1, “Text Selection”)
      If Button = 2 Then Exit Sub
      End If
      continue
      End Sub

      Note though that even an insertion point qualifies as a selection in this case.

      Also, why are you doing this? – if you use the Tools > Word Count directly in Word, with no more than an insertion point selected, then the dialog will give you the option to count footnotes and endnotes. Is it the case that you need to get a word count for just part of the document (but including footnotes and endnotes)?

      Gary

    • #559986

      On issue 1, I don’t see a cancel button in MS’ dialog (available at Word 2000 Tool: Selection Word Count Macro) so perhaps it was added without being “wired” to do anything and can simply be removed?

      On issue 2, maybe you should just get rid of the startrun() procedure and run WordCount() instead?

      Gary is correct that there is a built-in Word Count… function. It works best when there is no selection, that is, when you want a word count for the entire document. When you select text, the built-in function cannot count the words in the footnotes and endnotes, which is why MS wrote the above macro.

      • #559992

        Hi Jefferson,

        Thanks for the link to this utility – didn’t know it existed.

        It would seem to render jahbel’s project academic – which project appears to be an attempt to do the same thing the MS utility is doing (the dialog in this one being a custom userform “FrmWordCount”, the code for which was not included in the post).

        As for issue 1, I think this wasn’t a button on a built-in dialog but rather the button on the MsgBox here:

        Sub startrun()
        Button = MsgBox(“Select the portion of the Document that should be included in the Word Count.” + Chr(13) + “Court rules vary, please make sure your selection complies with applicable court rules”, 1, “Text Selection”)
        continue
        End Sub”

        – this MsgBox has OK and Cancel buttons, but the code as written isn’t doing anything with the return value of “Button”.

        BTW for a chuckle, look at the code behind the userform in the MS utility, it’s got some classic ‘oops’ inclusions like:

        Private Sub Frame3_Click()

        End Sub

        Private Sub IncludeEndnotes_Click()

        End Sub

        Private Sub Label2_Click()

        End Sub

        Private Sub UserForm_Click()

        End Sub

        (nothing wrong with accidentally creating event procedures by clicking on parts of the userform, but you’re suppose’ta delete ’em before posting as an MS download! grin)

        Gary

        • #560053

          Thanks guys
          The cancel button is linked to a form that has Cancel and Ok. I work for a law firm that deal with the courts and we must submit word count for selected parts of the document that must include endnotes and footnotes. The MS macro does some of the job but it is not foolproof which I need for these users. In any event Garys’ suggestions were extremely informative and I was able to get the other parts together.
          Thanks

    Viewing 1 reply thread
    Reply To: Word Count Macro (Word 2000 )

    You can use BBCodes to format your content.
    Your account can't use all available BBCodes, they will be stripped before saving.

    Your information: