|
可试试如下批量转换成脚注的代码。尾注的做法也差不多,只是原文档没有进行必要的分节,尾注太多都集中在文档末尾,似不符常规。- Sub test()
- '查找匹配并据以插入脚注,删除原标记文本,未删除原注释文本
- Dim i As Integer
- Dim j As Integer
- Dim response As Integer
- Dim alocation() As Long '注释起始位置参数
- Dim fnreference() As String '注释编号
- Dim fntext() As String '注释编号及文本,假设文本中没有制表符,且只是一个段落内容
- Dim st As Single
-
- st = Timer
- Application.ScreenUpdating = False
- Documents.Add ActiveDocument.FullName
-
- If ActiveDocument.Footnotes.Count > 0 Then
- MsgBox "文档中已存在脚注,程序退出!"
- Exit Sub
- End If
- With ActiveDocument.Content.Find
- .MatchWildcards = True
- .Forward = False
- '查找原标记文本,该文本不能在段落开头,不判断编号是否按顺序排列
- Do While .Execute("[!^13][\[][0-9]@\-[0-9]@[\]]")
- With .Parent
- ReDim Preserve alocation(i)
- ReDim Preserve fnreference(i)
- alocation(i) = .Start + 1
- fnreference(i) = Mid(.Text, 2)
- End With
- i = i + 1
- Loop
-
- i = 0
- .Parent.EndOf wdStory
- '查找原注释文本,该文本应为整个段落
- Do While .Execute("^13[\[][0-9]@\-[0-9]@[\]][!^13]")
- With .Parent
- .SetRange .Start + 1, .Paragraphs(2).Range.End - 1
- ReDim Preserve fntext(i)
- fntext(i) = Split(.Text, "]")(0) & "]" & vbTab & Mid(.Text, InStr(.Text, "]") + 1)
- '标记编号与注释条目编号不对应时选定问题注释文本后退出程序
- If Split(fntext(i), vbTab)(0) <> fnreference(i) Then
- .Select
- MsgBox "标记编号与注释编号不对应!"
- Exit Sub
- End If
- .Collapse wdCollapseStart
- End With
- i = i + 1
- Loop
- End With
-
- ActiveDocument.Range.FootnoteOptions.Location = wdBottomOfPage '
- For i = 0 To UBound(alocation)
- With ActiveDocument.Range(alocation(i), alocation(i) + Len(fnreference(i)))
- .Text = "" '测试时可不用本行,以对照
- .Footnotes.Add .Duplicate, fnreference(i), Split(fntext(i), vbTab)(1) '沿用自定义脚注标记文字
- ' .Footnotes.Add .Duplicate, fnreference(i), fntext(i) '测试时可用本行对照,不用上一行
- End With
- Next
- Documents.Add.Content.Text = "脚注标记与注释文本如下:" & vbCrLf & Join(fntext, vbCrLf)
- MsgBox "共插入了" & i & "个脚注。处理后的文档及脚注列表见新文档。用时" & Int(Timer - st) & "秒"
- Application.ScreenUpdating = True
- End Sub
复制代码 |
评分
-
1
查看全部评分
-
|