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