Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

Need MS Word Macro to replace footnotes and endnotes

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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

This article will show you how to use shortcut menus in the Access run-time environment.
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
This video shows the viewer how to set up and create Footnotes in their document. Click on the References tab: Select "Insert Footnote": Type in desired text:
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…

829 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