MS Word:自動搜尋字串並轉換為註腳

MS Word:自動搜尋字串並轉換為註腳

我搜尋過這個問題的變體,但沒有找到類似的東西。

我有一組 Word 文檔,其中包含兩種類型的內聯引用。第一個是標準學術引文,已透過 Zotero 插入,並且需要保持不變並連結到 Zotero。

第二種類型是明文,需要在同一點轉換為腳註,並刪除其括號。第二種類型的引文總是以「(File XX_XX」開頭,其中 X 是整數,或「(數位檔案」。

如果第二種類型的所有引文都可以立即轉換為腳註,那將有很大幫助。如果做不到這一點,將選定文字轉換為腳註並刪除其括號的巨集也可以工作。我現在已經成功地錄製了一個巨集來逐一執行這些操作,但是如果有一種方法可以在整個文件中自動執行該過程,那就太好了。

希望您能提供協助,並提前致謝。

以下是包含兩種引用類型的範例段落:

豪登省政府擔任機構職務的第二個領域是公共運輸業者的監管。 2000 年《國家陸路交通轉型法》設立了省級運營許可證委員會,全權負責向所有公共交通運營商頒發基於路線的運營許可證(Cameron,2005 年;Wosiyana,2005 年;Palmer、Moodley 和Parnell, 2017 年)。這些 OLB 負責管理舊的基於半徑的許可證向基於路線的運營許可證的轉換,以及在市政府的指導下頒發新許可證。然而,到 Rea Vaya 時,豪登省 OLB 已“陷入行政混亂”,幾乎停止發放運營許可證,約翰內斯堡市只能根據尚未處理的許可證申請的收據來計算可能受影響的運營商(文件03_05, BRT 第1a 階段約翰尼斯堡市和計程車產業參與會議聯合工作小組,2010 年3 月26 日)。

最後的引文必須是註腳,內容如下:

文件 03_05,BRT 第 1a 階段約翰尼斯堡市和計程車產業參與會議聯合工作小組,2010 年 3 月 26 日

答案1

類似這樣的事情,但是您必須決定要付出多少努力才能使其正常工作以及需要手動修復多少。

Sub NotesToFootnotes1()
'
Const matchcount As Integer = 2
Dim i As Integer
Dim r As Word.Range
Dim rStart As Word.Range
Dim fn As Word.Footnote
Dim s(1 To matchcount, 1 To 2) As String
' This uses a wildcard search which looks for 3 "groups"
' The first is a "("
' The second is the 'body' of the footnote
' The third is a ")"
s(1, 1) = "([(])(File [0-9][0-9]_[0-9][0-9]*)([)])"
' This replaces the found text by the content of the second group.
s(1, 2) = "\2"
s(2, 1) = "([(])(Digital file*)([)])"
s(2, 2) = "\2"
For i = 1 To matchcount
  Set r = ActiveDocument.Content
  With r.Find
    .Text = s(i, 1)
    .Replacement.Text = s(i, 2)
    .Forward = True
    .Wrap = wdFindStop
    .Format = False
    ' This wil actually match Digital fIle, Digital File, DIGITAL FILE etc.
    ' If you only want to match Digital file, set it to False
    .MatchCase = True
    .MatchWholeWord = False
    .MatchAllWordForms = False
    .MatchSoundsLike = False
    ' Very important!
    .MatchWildcards = True
    .Execute Replace:=True
    Do While .Found
      Set rStart = r.Duplicate
      rStart.Collapse WdCollapseDirection.wdCollapseStart
      ' Initially, create an empty footnote, because if we want to
      ' put formatted text in the footnote, we can't do it in the .Add
      With rStart.Footnotes.Add(Range:=rStart, Text:="")
        ' Don't copy the newly inserted footnote reference!
        r.Start = r.Start + 1
        ' This copies the content of the range, which would include formatting
        ' possibly images and so on. If you don't want that, use
        ' .Range.Text = r.Text
        ' instead, but be aware that anything other than text will probably not
        ' copy exactly the way you expect.
        .Range.FormattedText = r.FormattedText
      End With
      Set rStart = Nothing
      r.Delete
      .Execute Replace:=True
    Loop
    Set r = Nothing
  End With
Next ' i
End Sub

相關內容