【问题标题】:VBA Macro to convert only certain footnotes to endnotes in Word?VBA宏仅将某些脚注转换为Word中的尾注?
【发布时间】:2015-04-02 02:21:37
【问题描述】:

第一次发帖,希望我做对了。

我有一个 Word 文档,其中有很多脚注都是自定义标记,没有一个是自动编号的。自定义标记有两种类型:数字和字母。所以要么 1、2、3 要么 a、b、c。 我只想将带有字母标记的脚注转换为尾注。

我可以将所有脚注转换为尾注:

Sub ConvertFootnotesEndnotesTEST()
' Convert
ActiveDocument.Footnotes.Convert
With ActiveDocument.Range(Start:=ActiveDocument.Content.Start, End:= _
ActiveDocument.Content.End).FootnoteOptions
.Location = wdBottomOfPage
.NumberStyle = wdNoteNumberStyleLowercaseLetter
End With
' Renumbering
With ActiveDocument.Range(Start:=ActiveDocument.Content.Start, End:= _
ActiveDocument.Content.End).EndnoteOptions
.Location = wdEndOfDocument
.NumberingRule = wdRestartContinuous
.StartingNumber = 1
.NumberStyle = wdNoteNumberStyleLowercaseArabic
End With
End Sub

我认为在上面规定 NumberStyle 是可行的;它没有。我不是真正的程序员,只是一个热心的 Word 用户。 我也试过了

If Selection.Footnotes.NumberStyle = wdNoteNumberStyleLowercaseLetter
Then Selection.Footnotes.Convert

但这也不起作用。

我将非常感谢您对此的帮助!谢谢你。

【问题讨论】:

    标签: vba ms-word footnotes


    【解决方案1】:

    无论出于何种原因,您都不能直接转换单个脚注。您也无法以您想要的方式查询号码样式;该数字样式将指示 Word 的连续字母注释,而不是自定义标记。因此,最好的方法可能是循环浏览文档中的每个脚注,确定它是否是您要转换的,然后将其转换为脚注集合的成员(它始终只包含一个注释)。我会这样做:

    Sub ConvSomeFootnotes()
    'Declare some variables.
    Dim objFNote As Footnote
    Dim objDoc As Document
    
        Set objDoc = ActiveDocument
    
        'Loop through each footnote in the document's footnotes collection.
        For Each objFNote In objDoc.Footnotes
            'This only works because you are using custom marks, which can be read as regular text. If you were using standard sequential markers you'd need a different approach.
            'Check that the text of the footnote reference matches the character class that contains all lowercase letters.
            If objFNote.Reference.Text Like "[a-z]" Then
                'If it does, we convert all of the footnotes within the range (which in this case happens to be just the one footnote we are looking at).
                objFNote.Reference.Footnotes.Convert
            End If
        Next objFNote
    End Sub
    

    正如 cmets 中所述,这仅在您使用自定义标记时才有效。如果不是,则需要另一种方法来判断脚注是字母还是编号(一种更复杂的方法)。我在 Word 2010 上对此进行了测试;我不能确定它是否可以在 Mac 或更早版本的 Word 中按原样工作。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-07-02
      • 2020-08-29
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多