Word 或 LibreOffice/OpenOffice - 如何在文档正文的脚注引用标记处自动插入脚注文本?

Word 或 LibreOffice/OpenOffice - 如何在文档正文的脚注引用标记处自动插入脚注文本?

我有一些 docx 文档,其中包含大量脚注,通常带有简短的脚注文本(例如“Richard 2010。”或“参见第 xy 节”)。将这些脚注放在文档正文中的括号[] 中代替脚注引用标记会方便得多。我在 Word 或 LibreOffice 中找不到此功能。我想我需要一个宏。

我在这里看到过将注释转换为脚注的宏。只有十行我花了一个晚上的时间尝试学习一些宏基础知识并修改一些现有的宏,但失败了。

答案1

起点:

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
Next

finish:
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
Next
cleanup = r
End Function

相关内容