# PDF to Word - Footnotes



## fredaxe (Apr 7, 2010)

Hi

I have a large document that i converted from PDF to word. The footnotes were converted across as regular text. Is there a macro to then convert that text to footnotes? In the conversion, there is the footnote number in the main text and again at the bottom of the page before the footnote. Or is there a way of converting a PDF to word that automatically recognises the footnotes and integrates them in the word doc?

I have never used macros before, but i don't want to manually work through this 900 page document.

Cheers


----------



## macropod (Apr 11, 2008)

Hi fredaxe,

Here's a macro to do the conversion, but you still need to manually select the footnotes before Word can process them - there's no way Word can tell for itself what plain text should or should not be treated as footnotes. Given that, the simplest way to process the footnotes would be to cut & paste them all to the end of of the document (in order) before running the macro. If that seems too much trouble, you could simply select the footnotes at the bottom of a given page and run the macro on a page-by-page basis.

```
Sub ReLinkFootNotes()
Dim i As Integer, j As Integer, k As Integer, l As Integer
Dim FtRng As Range
Application.ScreenUpdating = False
With ActiveDocument
  Set FtRng = Selection.Range
  With FtRng
    .Style = "Footnote Text"
    With .Find
      .ClearFormatting
      .Replacement.ClearFormatting
    ' Change or delete the '\[' and '\]' on the next line to whatever is appropriate if the selected
    ' footnotes' numbers are enclosed in characters other than square brackets
      .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
    k = .Paragraphs(1).Range.Words(1) - 1
    j = k
    l = ActiveDocument.Footnotes.Count - 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
  For i = k + 1 To j
    StatusBar = "Finding Footnote Location: " & i + l
    With .Content.Find
      ' Change '"[" & i & "]"' string on the next line to whatever is appropriate
      ' if the in-line references are not enclosed in square brackets
      .Text = "[" & i & "]"
      ' Delete/comment out the next line if not applicable
      .Font.Superscript = True
      .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 FtRng
    For i = k + 1 To j
      StatusBar = "Transferring Footnote: " & i + l
      With .Paragraphs(1).Range
        .Cut
        With ActiveDocument.Footnotes(i + l).Range
          .Paste
          .Words(1).Delete
          .Characters.Last.Delete
        End With
      End With
    Next i
  On Error Resume Next
  End With
  Set FtRng = Nothing
End With
Application.ScreenUpdating = True
End Sub
```
The macro assumes:
· The selected range contains the footnotes to be converted, with the first footnote number being, at most, enclosed in square brackets, thus [#], followed by a space. Comments in the code indicate where to make changes to suit other scenarios
· you’ll be using Wor'd "Footnote Text" style for the 'real' footnotes. If not, you can simply change it in the line:
.Style = "Footnote Text"
· 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 also shows its progress on the status bar.


----------

