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

时间:2017-10-03 03:08:57

标签: ms-word word-vba

我有一个很好的宏,用于将页码插入到MS Word尾注here的开头:

^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

进入

java.lang.IllegalArgumentException: Buffer size <= 0
at java.io.BufferedInputStream.<init>(BufferedInputStream.java:201)
at org.eclipse.osgi.framework.internal.reliablefile.ReliableFile.getInputStream(ReliableFile.java:272)
at org.eclipse.osgi.framework.internal.reliablefile.ReliableFileInputStream.<init>(ReliableFileInputStream.java:92)
at org.eclipse.osgi.framework.internal.reliablefile.ReliableFileInputStream.<init>(ReliableFileInputStream.java:66)
at org.eclipse.osgi.storagemanager.StorageManager.updateTable(StorageManager.java:487)
at org.eclipse.osgi.storagemanager.StorageManager.open(StorageManager.java:708)
at org.eclipse.osgi.storage.Storage.getChildStorageManager(Storage.java:1749)
at org.eclipse.osgi.storage.Storage.getInfoInputStream(Storage.java:1766)
at org.eclipse.osgi.storage.Storage.<init>(Storage.java:126)
at org.eclipse.osgi.storage.Storage.createStorage(Storage.java:85)
at org.eclipse.osgi.internal.framework.EquinoxContainer.<init>(EquinoxContainer.java:75)
at org.eclipse.osgi.launch.Equinox.<init>(Equinox.java:31)
at org.eclipse.core.runtime.adaptor.EclipseStarter.startup(EclipseStarter.java:295)
at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:231)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:497)
at org.eclipse.equinox.launcher.Main.invokeFramework(Main.java:648)
at org.eclipse.equinox.launcher.Main.basicRun(Main.java:603)
at org.eclipse.equinox.launcher.Main.run(Main.java:1465)
at org.eclipse.equinox.launcher.Main.main(Main.java:1438)

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

1 个答案:

答案 0 :(得分:1)

这应该可以胜任。

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