繁体   English   中英

如何删除 MS Word 尾注的前两个单词

[英]How to remove first two words of a MS Word Endnote

我有一个伟大的宏尾插入页码,以MS Word的开始在这里

Sub InsertPageNumberForEndnotes()
Dim endNoteCount As Integer
Dim curPageNumber As Integer
If ActiveDocument.Endnotes.Count > 0 Then
  For endNoteCount = 1 To ActiveDocument.Endnotes.Count
    Selection.GoTo What:=wdGoToEndnote, Which:=wdGoToAbsolute, _
      Count:=endNoteCount
    curPageNumber = Selection.Information(wdActiveEndPageNumber)
    ActiveDocument.Endnotes(endNoteCount).Range.Select
    ActiveDocument.Application.Selection.Collapse _
      (WdCollapseDirection.wdCollapseStart)
    ActiveDocument.Application.Selection.Paragraphs(1).Range.Characters(3)._
      InsertBefore "Page " & CStr(curPageNumber) & ". "        
  Next
End If    
End Sub

哪个处理来自的尾注

^1 Blah blah blah
^2 Blah blah blah 
^3 Blah blah blah

进入

^1 Page 2. Blah blah blah
^2 Page 23. Blah blah blah 
^3 Page 119. Blah blah blah

我现在需要第二个宏来通过删除“Page nn -”来“撤消”更改,以便我可以重新运行宏以刷新页码。 我的想法是我需要选择以“Page”开头的每个尾注的前 3 个单词,或者选择直到第一个“-”字符索引的范围? 我需要对上述宏进行哪些更改才能选择和删除添加的文本?

这应该可以完成工作。

Sub InsertPageNumberForEndnotes()
    ' 04 Oct 2017

    Dim Note As EndNote
    Dim Sp() As String
    Dim n As Long

    For Each Note In ActiveDocument.Endnotes
        With Note.Range
            ' remove "vbTextCompare" to make the search case sensitive
            n = InStr(1, .Text, "page", vbTextCompare)
            If n Then               ' you could make this "If n = 1"
                m = InStr(1, Txt, ". ")
                .Text = Mid(Txt, m + 2)
            End If
        End With
    Next Note
End Sub

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM