Solved

Need MS Word Macro to replace footnotes and endnotes

Posted on 2011-09-20
2
643 Views
Last Modified: 2012-06-27
So there is an application that we load documents into that just cannot handle footnotes and endnotes in a MSWord document. So I need to code something that takes each footnote and endnote in a document and replaces it. I need the code to copy the footnote and/or endnote text and then paste the text where the footnote or endnote mark is, then delete the footnote or endnote. So the end goal is the footnote and endnote text ends up where the mark was and there is not longer footnotes and endnotes in the document.

I've attached a before and after document of basically what I want to occur in the document. I added the text "Footnote: " and "Endnote:" and put the replacement in parenthesis because although I think it would give an idea to the user exactly why its not nicely formatted and just kinda jammed into the middle of the document. But if thats more work and its just easier to dump the note in place of the mark then I'm fine with that.
Before.doc
After.doc
0
Comment
Question by:KGNickl
2 Comments
 
LVL 17

Accepted Solution

by:
andrewssd3 earned 500 total points
ID: 36567230
Here is a macro that does what you ask:

Public Sub ReplNotes()

    Dim d As Word.Document
    Dim f As Footnote
    Dim e As Endnote
    Dim i As Long
    Dim strText As String
    Dim rngRef As Word.Range
    
    Set d = ThisDocument
    
    For i = d.Footnotes.Count To 1 Step -1
        Set f = d.Footnotes(i)
        strText = f.Range.Text
        
        Set rngRef = f.Reference
        
        rngRef.Delete
        rngRef.InsertAfter " (Footnote: " & strText & ") "
        
    Next i

    For i = d.Endnotes.Count To 1 Step -1
        Set e = d.Endnotes(i)
        strText = e.Range.Text
        
        Set rngRef = e.Reference
        
        rngRef.Delete
        rngRef.InsertAfter " (Endnote: " & strText & ") "
        
    Next i

End Sub

Open in new window


Just locate and run the macro ReplNotes - I attach your Before file with macro added Before.doc
0
 
LVL 5

Author Closing Comment

by:KGNickl
ID: 36567525
I haven't tried it, but will assume it works. I actually finished the perl code for the same between posting this question and seeings your questions. After digging in the word API for a few minutes I realized it was actually pretty easy to do.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

No matter the version of Windows you are using, you may have some problems with Windows Search running too slow or possibly not running at all. Before jumping into how you can solve this issue, just know there are many other viable alternative deskt…
This article will guide you to convert a grid from a picture into Excel format using Microsoft OneNote and no other 3rd party application.
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…
The viewer will learn how to create a normally distributed random variable in Excel, use a normal distribution to simulate the return on an investment over a period of years, Create a Monte Carlo simulation using a normal random variable, and calcul…

932 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

12 Experts available now in Live!

Get 1:1 Help Now