Word: Convert smart endnotes into dumb ones

Soldato
Joined
28 Dec 2003
Posts
3,737
Location
Aberwristwatch
I need to do this in Word 2003 so that when I paste the endnotes into a separate document, the numbers don't all turn into '1'. I've found this macro online but it's failing to run. "Compile error: Invalid Outside Procedure"

Any ideas?

Code:
' Macro created 29/09/99 by Doug Robbins to replace footnotes with textnotes
at end of document

' to replace the footnote reference in the body of the document with a
superscript number.

'

Dim afnote As Endnote

For Each afnote In ActiveDocument.footnotes

ActiveDocument.Range.InsertAfter vbCr & afnote.Index & vbTab &
afnote.Range

afnote.Reference.InsertBefore "a" & afnote.Index & "a"

Next afnote

For Each afnote In ActiveDocument.Footnotes

afnote.Reference.Delete

Next afnote

Selection.Find.ClearFormatting

Selection.Find.Replacement.ClearFormatting

With Selection.Find.Replacement.Font

.Superscript = True

End With

With Selection.Find

.Text = "(a)([0-9]{1,})(a)"

.Replacement.Text = "\2"

.Forward = True

.Wrap = wdFindContinue

.Format = True

.MatchWildcards = True

End With

Selection.Find.Execute Replace:=wdReplaceAll
 
Last edited:
No, I don't think it was. Have done so now and getting the following:

Run-time error '13':
Type mismatch

On clicking OK, it takes me back into Visual Basic Editor and highlights the first line in yellow

"For Each afnote In ActiveDocument.Footnotes"
 
yeah, the variable at the top afnote is defined as an Endnote which the highlighted line is trying to jam a Footnote into.
If you have foot notes, change the variable to footnote. Other wise change the lines
ActiveDocument.Footnotes
to
ActiveDocument.Endnotes
 
Having a think about what you actually want it to do I've rewritten it like this for you.
This will pick up any endnotes and move them into the body of the document preserving their formatting other than the smart quotes.
Code:
Sub test()
'
' test Macro
'
'
'Application.ScreenUpdating = False
howitwas = Options.AutoFormatAsYouTypeReplaceQuotes
Options.AutoFormatAsYouTypeReplaceQuotes = False

Dim afnote As Endnote
For Each afnote In ActiveDocument.Endnotes
    afnote.Range.FormattedText.Copy
    
    ActiveDocument.Range.InsertAfter vbCr & afnote.Index & vbTab
    
    Set rng = ActiveDocument.Content
    rng.Collapse wdCollapseEnd
    rng.PasteAndFormat (wdFormatOriginalFormatting)
    
    afnote.Reference.InsertBefore "a" & afnote.Index & "a"
    
Next afnote

For Each afnote In ActiveDocument.Endnotes
    afnote.Reference.Delete
Next afnote

With Selection.Find
    .Text = "(a)([0-9]{1,})(a)"
    .Replacement.Text = "\2"
    .Replacement.Font.Superscript = True
    .Forward = True
    .Wrap = wdFindContinue
    .Format = True
    .MatchWildcards = True
    .Execute Replace:=wdReplaceAll
    
    .Format = False
    .Text = "[“”]"
    .Replacement.Text = Chr(34)
    .Execute Replace:=wdReplaceAll
    .Text = "[‘’]"
    .Replacement.Text = Chr(39)
    .Execute Replace:=wdReplaceAll
End With

Options.AutoFormatAsYouTypeReplaceQuotes = howitwas

'Application.ScreenUpdating = True
End Sub
 
it's a hack but you could try a doevents loop in there. It will of course make the thing run really slowly.
So add this sub below the end sub of your main macro and then on line 19 of the original macro put
wait (1)
Code:
Sub Wait(n As Long)
    Dim t As Date
    t = Now
    Do
        DoEvents
    Loop Until Now >= DateAdd("s", n, t)
End Sub
 
Back
Top Bottom