?
Solved

Need MS Word Macro to replace footnotes and endnotes

Posted on 2011-09-20
2
Medium Priority
?
658 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
[X]
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
2 Comments
 
LVL 17

Accepted Solution

by:
andrewssd3 earned 2000 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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

Access developers frequently have requirements to interact with Excel (import from or output to) in their applications.  You might be able to accomplish this with the TransferSpreadsheet and OutputTo methods, but in this series of articles I will di…
Cancel future meetings from user mailboxes in Office 365 using Remove-CalendarEvents
The viewer will learn how to simulate a series of sales calls dependent on a single skill level and learn how to simulate a series of sales calls dependent on two skill levels. Simulating Independent Sales Calls: Enter .75 into cell C2 – “skill leve…
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…

764 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