Results 1 to 5 of 5
  1. #1
    New Lounger
    Join Date
    Dec 2001
    Location
    New York, New York, Thailand
    Posts
    15
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Word Count Macro (Word 2000 )

    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

  2. #2
    Super Moderator
    Join Date
    Dec 2000
    Location
    New York, NY
    Posts
    2,970
    Thanks
    3
    Thanked 29 Times in 27 Posts

    Re: Word Count Macro (Word 2000 )

    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?<g> - 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

  3. #3
    Super Moderator jscher2000's Avatar
    Join Date
    Feb 2001
    Location
    Silicon Valley, USA
    Posts
    23,112
    Thanks
    5
    Thanked 93 Times in 89 Posts

    Re: Word Count Macro (Word 2000 )

    On issue 1, I don't see a cancel button in MS' dialog (available at <A target="_blank" HREF=http://office.microsoft.com/downloads/2000/swcmacro.aspx>Word 2000 Tool: Selection Word Count Macro</A>) 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.

  4. #4
    Super Moderator
    Join Date
    Dec 2000
    Location
    New York, NY
    Posts
    2,970
    Thanks
    3
    Thanked 29 Times in 27 Posts

    Re: Word Count Macro (Word 2000 )

    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! <img src=/S/grin.gif border=0 alt=grin width=15 height=15>)

    Gary

  5. #5
    New Lounger
    Join Date
    Dec 2001
    Location
    New York, New York, Thailand
    Posts
    15
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Word Count Macro (Word 2000 )

    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

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •