I have some docx documents that contain a lot of footnotes with usually a short footnote text (e.g. "Richard 2010." or "see section xy"). It's much more convenient to have these in the document body in brackets[] at and in lieu of the footnote reference mark. I don't find a function for this in Word or LibreOffice. I guess I need a macro.

I have seen here a macro that converts comments into footnotes. It's only ten lines. I tried for one night to learn some macro basics and modify some existing macros but failed miserably.


A starting point:

Sub bootNoteIntoBody()
Dim bScreenUpdating As Boolean
Dim oDoc As Document
Dim oNote As Footnote
Dim rng As Range
Dim strStyleName As String

bScreenUpdating = Application.ScreenUpdating
On Error GoTo finish
Application.ScreenUpdating = False
Set oDoc = ActiveDocument
For Each oNote In ActiveDocument.Footnotes
  ' choose your own maximum length
  If Len(oNote.Range.Text) < 20 Then
    Set rng = oNote.Reference
    With rng
      strStyleName = .Style
      .Text = "[" & cleanup(oNote.Range.Text) & "]"
      .Style = strStyleName
    End With
  End If

Application.ScreenUpdating = bScreenUpdating

End Sub

Function cleanup(s As String) As String
' replace certain characters by space.
Dim i As Integer
Dim r As String
r = ""
For i = 1 To Len(s)
  Select Case AscW(Mid(s, i, 1))
    Case 1 To 31 ' and perhaps others
      r = r & " "
    Case Else
      r = r & Mid(s, i, 1)
  End Select
cleanup = r
End Function

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.