Wow, macropod, that is amazing. Here are my findings:
First, you answered my question about how to search for a
variable:
.Text = "[" & i & "]"
Second, I first stepped through the macro, testing it on a
one-footnote chapter. It worked perfectly. Awesome!
Then, in the second chapter of the two-chapter document, which
has maybe 15 footnotes, I selected the whole block and let her
rip. The first footnote, [2], was converted perfectly. But the
macro seemed to choke for a while (said it was converting
footnote 2) and none of the other footnotes were converted.
Moreover, the footnote numbers in the block of footnote text were
stripped of their brackets.
So I undid the changes and tried Chapter Two again. I found that
I needed to start with the first footnote, over in Chapter One,
or else the numbering would error out. I don't think that will be
a problem.
So I started again in Chapter One. Again the macro worked
perfectly, but now I noticed that it had gone ahead and stripped
the brackets off the footnote numbers of the footnote text in
Chapter Two, which I think is self-defeating.
So I think there are two issues I've unearthed. First, the search
for brackets to strip needs to be relegated to the selected
block. Second, somehow the larger block of about 15 footnotes is
choking the macro.
The file I used is 5 pages long, 56K on the hard drive. The first
chapter consists of one page, two words, and a one-sentence
footnote.
Thanks so much for expending effort on this. I think this is a
very classy"teaching" macro, that one can learn a lot from.
bw,
p.
Hi Paul,
Try the following macro:
Sub ReLinkFootNotes()
Dim i As Integer
Dim j As Integer
Dim k As Integer
Application.ScreenUpdating = False
With Selection
With .Find
.ClearFormatting
.Replacement.ClearFormatting
.Text = "\[([0-9]{1,})\]"
.Replacement.Text = "\1"
.Forward = True
.Wrap = wdFindStop
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchAllWordForms = False
.MatchSoundsLike = False
.MatchWildcards = True
.Execute Replace:=wdReplaceAll
End With
.Bookmarks.Add Range:=.Range, Name:="FootNotes"
k = .Paragraphs(1).Range.Words(1) - 1
j = k
For i = 1 To .Paragraphs.Count
If .Paragraphs(i).Range.Words(1) = j + 1 Then
j = j + 1
End If
Next i
End With
With ActiveDocument
For i = k + 1 To j
StatusBar = "Finding Footnote Location: " & i
With .Content.Find
.Text = "[" & i & "]"
.MatchWholeWord = True
.MatchWildcards = False
.Execute
If .Found = True Then
.Parent.Select
With Selection
.Delete
.Footnotes.Add Range:=Selection.Range, Text:=""
End With
End If
End With
Next i
With .Bookmarks("FootNotes").Range
.Style = "Footnote Text"
For i = k + 1 To j
StatusBar = "Transferring Footnote: " & i
With .Paragraphs(1).Range
.Cut
With ActiveDocument.Footnotes(i).Range
.Paste
.Words(1).Delete
.Characters.Last.Delete
End With
End With
Next i
On Error Resume Next
End With
.Bookmarks("FootNotes").Delete
End With
Application.ScreenUpdating = True
End Sub
All you should need to do is to select the block of footnotes to be converted. The macro assumes each footnote consists of a single
paragraph. If you have any multi-paragraph footnotes, you can get around that issue by changing their internal paragraph markers to
line feeds (i.e. Shift-Enter) before running the macro.
The macro is coded to show its progress on the status bar.