Macro to count EndNote references in selected Word 2010 text

Posted on 2012-09-06
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 76

    Accepted Solution

    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

    This works brilliantly GrahamSkan! Thank you so much!

    Featured Post

    IT, Stop Being Called Into Every Meeting

    Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

    Join & Write a Comment

    This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
    Deploying a Microsoft Access application in a Citrix environment is not difficult but takes a few steps. However, Citrix system people are often of little help, as they typically know next to nothing about Access. The script provided here will take …
    The viewer will learn how to simulate a series of coin tosses with the rand() function and learn how to make these “tosses” depend on a predetermined probability. Flipping Coins in Excel: Enter =RAND() into cell A2: Recalculate the random variable…
    The viewer will learn how to use the =DISCRINV command to create a discrete random variable, use this command to model a set of probabilities and outcomes in a Monte Carlo simulation, and learn how to find the standard deviation of a set of probabil…

    734 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

    Need Help in Real-Time?

    Connect with top rated Experts

    23 Experts available now in Live!

    Get 1:1 Help Now