Macro to count EndNote references in selected Word 2010 text

Posted on 2012-09-06
Medium Priority
Last Modified: 2012-09-06
Good afternoon experts, I am hoping to get some help with a macro for Word 2010.  The goal of the macro is to count the number of EndNote formatted references (super script numbers with some formatting) that are selected by the user and display the number in a message box.  The purpose of this is to help in fact-checking academic documents which are routinely used and contain many references.  This is accomplished with manual counting currently which is time consuming and can be prone to error.  I would appreciate any help that EE can offer with this problem.  I’ve attached an example Word document to this post.  

Thanks again for any feedback as always,
Question by:Bevos
LVL 77

Accepted Solution

GrahamSkan earned 2000 total points
ID: 38373779
These aren't Word Endnotes, but  are Word Addin fields produced by a third party product.

There is no actual text highlighting in the document, so I suppose that you are referring to the Selection. Try this
Sub CountNotes()
    Dim fld As Field
    Dim strResult As String
    Dim iCount As Integer
    Dim strRefs() As String
    Dim strSpan As String
    Dim strEnds() As String
    Dim i As Integer
    For Each fld In Selection.Fields
        If fld.Type = wdFieldAddin Then
            strResult = fld.Result
            If Len(strResult) > 0 Then
                strRefs = Split(strResult, ",")
                For i = 0 To UBound(strRefs)
                    iCount = iCount + 1
                    strEnds = Split(strRefs(i), "-")
                    If UBound(strEnds) = 1 Then
                        iCount = iCount + Val(strEnds(1)) - Val(strEnds(0))
                    End If
                Next i
            End If
        End If
    Next fld
    MsgBox iCount & " references counted"
End Sub

Open in new window

It isn't clear how the number in the text is to be found. Is it to find any number (in word or words) in the text, and to convert to an actual number for comparison?

Author Comment

ID: 38374152
This works brilliantly GrahamSkan! Thank you so much!

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Article by: Leon
Software Metering within our group of companies has always been an afterthought until auditing of software and licensing became a pain point. Orchestrator and SCCM metering gave us the answer and it was an exciting process.
Microsoft's Excel has many features that most people will never need nor take advantage of.  Conditional formatting is one feature that you may find a necessity once you start using it.
This video walks the viewer through the process of creating Hyperlinks for the web and other documents. Select the "Insert" tab: Click "Hyperlink":  Type "http://" followed by a web address to reference a website or navigate to a document to ref…
The viewer will learn how to use a discrete random variable to simulate the return on an investment over a period of years, create a Monte Carlo simulation using the discrete random variable, and create a graph to represent the possible returns over…
Suggested Courses

621 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question