View Single Post
 
Old 01-28-2012, 03:07 PM
macropod's Avatar
macropod macropod is online now Windows 7 64bit Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 22,366
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

Hi Ken,

With the sample.doc you posted, does the Run-time error 4605 occur on that when you use the code I posted? If so, how much of the processing has been done at that stage (it might be easier to see if you uncomment the line 'Application.ScreenUpdating = False' before running the code)?

Both Doug's code (supplied by Stefan) and mine run to completion on a PC, so (assuming the answer to the first question above is yes) the errors seem to be either Mac-specific or specific to just your system. Maybe there's a fault with the Word installation on your system - that seems possible since neither the Find/Replace routine in Doug's code nor some aspect of my code work correctly. Be that as it may, you should be able to process the 'aXa' content left over from Doug's code with a wildcard Find/Replace (that's what the macro tries to do), where:
Find = a([0-9]{1,})a
Replace = \1
and the replacement font is set to superscript.

Finally, here's another two macros to try. The first is a modified version of Doug's code. It should retain both your endnote formatting and superscript the numbers. The second is a quite different macro I've written that will also preserve non-numeric endnote references (you previous reference to [i] suggested you were actually using roman numerals).
Code:
Sub ConvertEndNotes()
Application.ScreenUpdating = False
Dim aendnote As Endnote, Rng As Range
With ActiveDocument
  .Range.InsertAfter vbCr
  For Each aendnote In .Endnotes
    Set Rng = .Range.Characters.Last
    Rng.Style = "Endnote Text"
    With aendnote
      .Range.Copy
      Rng.InsertAfter vbCr & "[" & .Index & "] "
      Rng.Collapse wdCollapseEnd
      Rng.Paste
      .Reference.InsertBefore "[" & .Index & "]"
    End With
  Next aendnote
  For Each aendnote In .Endnotes
    aendnote.Reference.Delete
  Next aendnote
  With .Content.Find
    .ClearFormatting
    .Replacement.ClearFormatting
    .Text = "\[([0-9]{1,})\]"
    .Replacement.Style = "Endnote Reference"
    .Replacement.Text = "\1"
    .Forward = True
    .Wrap = wdFindContinue
    .Format = True
    .MatchWildcards = True
    .Execute Replace:=wdReplaceAll
  End With
End With
Set Rng = Nothing
Application.ScreenUpdating = True
End Sub
Code:
Sub UnLinkNotes()
Application.ScreenUpdating = False
Dim nRng As Range, eNote As Endnote, nRef As String
With ActiveDocument
  For Each eNote In .Endnotes
    With eNote
      With .Reference.Characters.First
        .Collapse wdCollapseStart
        .InsertCrossReference wdRefTypeEndnote, wdEndnoteNumberFormatted, eNote.Index
        nRef = .Characters.First.Fields(1).Result
        .Characters.First.Fields(1).Unlink
      End With
      .Range.Cut
    End With
    Set nRng = .Range
    With nRng
      .InsertAfter vbCr & nRef & " "
      With .Paragraphs.Last.Range
        .Style = "Endnote Text"
        .Words.First.Style = "Endnote Reference"
      End With
      .Collapse wdCollapseEnd
      .Paste
    End With
  Next
  For Each eNote In .Endnotes
    eNote.Delete
  Next
End With
Set nRng = Nothing
Application.ScreenUpdating = True
End Sub
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote