MS Word: 文字列を自動的に検索して脚注に変換する

MS Word: 文字列を自動的に検索して脚注に変換する

この質問のバリエーションを探しましたが、似たようなものは見つかりませんでした。

2 種類のインライン引用を含む Word 文書のセットがあります。1 つ目は標準的な学術引用で、Zotero で挿入されており、そのままにして Zotero にリンクする必要があります。

2 番目のタイプはプレーンテキストであり、括弧を削除して同じポイントで脚注に変換する必要があります。2 番目のタイプの引用は常に「(ファイル XX_XX」(X は整数)、または「(デジタル ファイル」で始まります。

この 2 番目のタイプの引用をすべて一度に脚注に変換できれば、非常に役立ちます。それができない場合は、選択したテキストを脚注に変換し、その括弧を削除するマクロも機能します。今では、それらを 1 つずつ実行するマクロを記録することができましたが、ドキュメント全体でプロセスを自動化する方法があれば、さらに便利です。

ご協力いただければ幸いです。よろしくお願いいたします。

両方のタイプの引用を含むサンプル段落を次に示します。

ハウテン州政府が制度的に権限を握っていた 2 つ目の分野は、公共交通機関の規制です。2000 年の国家陸上交通移行法により、すべての公共交通機関の運行ルートに基づく運行ライセンスの発行を単独で担当する州運行ライセンス委員会が設立されました (Cameron、2005 年、Wosiyana、2005 年、Palmer、Moodley、Parnell、2017 年)。これらの運行ライセンス委員会は、半径に基づく古い許可証をルートに基づく運行ライセンスに変換する管理と、市町村政府の指導による新しいライセンスの発行を担当しました。しかし、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

関連情報