【发布时间】:2022-03-26 18:29:27
【问题描述】:
我正在尝试将文本注释(文本正文中的注释和引用)转换为具有现有尾注的 MS Word 文档中的尾注的方法,这是我几十年来的第一个宏。 我的文本注释可以被识别,因为它们在大括号之间是深蓝色的。到目前为止,我设法为单个步骤记录了一个宏:搜索模式、剪切模式、插入尾注、粘贴模式、在尾注中再次搜索模式、删除花括号、焦点回到文档的开头(在尾注之外)。
这是它的外观:
Sub inline2endnote()
Selection.Find.ClearFormatting
Selection.Find.Font.Color = 6299648
Selection.Find.Replacement.ClearFormatting
With Selection.Find
.Text = "\{(*?)\}"
.Replacement.Text = "\1"
.Forward = True
.Wrap = wdFindContinue
.Format = True
.MatchCase = False
.MatchWholeWord = False
.MatchAllWordForms = False
.MatchSoundsLike = False
.MatchWildcards = True
End With
Selection.Find.Execute
Selection.Cut
With Selection
With .EndnoteOptions
.Location = wdEndOfDocument
.NumberingRule = wdRestartContinuous
.StartingNumber = 1
.NumberStyle = wdNoteNumberStyleArabic
End With
.Endnotes.Add Range:=Selection.Range, Reference:=""
End With
Selection.PasteAndFormat (wdFormatOriginalFormatting)
Selection.Find.ClearFormatting
Selection.Find.Font.Color = 6299648
Selection.Find.Replacement.ClearFormatting
With Selection.Find
.Text = "\{(*?)\}"
.Replacement.Text = "\1"
.Forward = True
.Wrap = wdFindContinue
.Format = True
.MatchCase = False
.MatchWholeWord = False
.MatchAllWordForms = False
.MatchSoundsLike = False
.MatchWildcards = True
End With
Selection.Find.Execute
With Selection
If .Find.Forward = True Then
.Collapse Direction:=wdCollapseStart
Else
.Collapse Direction:=wdCollapseEnd
End If
.Find.Execute Replace:=wdReplaceOne
If .Find.Forward = True Then
.Collapse Direction:=wdCollapseEnd
Else
.Collapse Direction:=wdCollapseStart
End If
.Find.Execute
End With
Selection.HomeKey Unit:=wdStory
End Sub
我不得不重新关注顶部,因为我需要退出尾注部分并返回正文。另外,我不知道最后一个“With”部分是什么意思。 现在我想循环这个模式以修复所有的内联注释,但我似乎无法找到。我使用this thread 作为参考,但我无法弄清楚如何正确设置我的范围并为我的迭代定义字段。 我还想知道是否有一种更简洁的方法来编写这些步骤,例如直接粘贴不带大括号的内容,例如将我的查找存储在一个变量中并使用第二个带有剥离内容的变量。
【问题讨论】: