VBA宏是否仅将某些脚注转换为Word中的尾注?

VBA宏是否仅将某些脚注转换为Word中的尾注?,vba,ms-word,footnotes,Vba,Ms Word,Footnotes,第一篇文章,希望我做得对 我有一个Word文档,有很多脚注,都是自定义标记,没有自动编号的。自定义标记有两种类型:数字和字母。所以要么是1,2,3,要么是a,b,c。 我只想把带字母标记的脚注转换成尾注 我可以使用以下命令将所有脚注转换为尾注: Sub ConvertFootnotesEndnotesTEST() ' Convert ActiveDocument.Footnotes.Convert With ActiveDocument.Range(Start:=ActiveDocument.C

第一篇文章,希望我做得对

我有一个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
我认为在上面规定数字类型是可行的;没有。我不是一个真正的程序员,只是一个热衷于文字的用户。 我也试过了

If Selection.Footnotes.NumberStyle = wdNoteNumberStyleLowercaseLetter
Then Selection.Footnotes.Convert
但这也不行


我将非常感谢您的帮助!谢谢

无论出于何种原因,您都不能直接转换单个脚注。您也不能以您想要的方式查询数字样式;该数字样式将指示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
如注释中所述,这仅适用于使用自定义标记的情况。如果你没有,你需要另一种方法来判断脚注是字母还是编号(更复杂的方法)。我在Word 2010上测试了这一点;我不能确定它是否能像Mac或更早版本的Word那样工作