Solved

Need MS Word Macro to replace footnotes and endnotes

Posted on 2011-09-20
2
641 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

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

Recently Microsoft released a brand new function called CONCAT. It's supposed to replace its predecessor CONCATENATE. But how does it work? And what's new? In this article, we take a closer look at all of this - we even included an exercise file for…
This article descibes how to create a connection between Excel and SAP and how to move data from Excel to SAP or the other way around.
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…
Learn how to create and modify your own paragraph styles in Microsoft Word. This can be helpful when wanting to make consistently referenced styles throughout a document or template.

708 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

16 Experts available now in Live!

Get 1:1 Help Now