首页 > 解决方案 > 将脚注导出到新文档

问题描述

我需要 vba 代码将 MSWord 文档中的所有脚注复制到单独的文档中。我希望它在原始文档中使用相同的编号进行排序。

我已经尝试了以下代码,但它什么也没显示。

    Dim s As String
    Dim ftnt As Word.Footnotes
    Dim doc As Word.Document
    Dim xRange As Range
    Dim countNum As Integer
    Set xDoc = ActiveDocument
    countNum = 0
    
    Do Until countNum = ActiveDocument.Range.Information(wdNumberOfPagesInDocument)
            Set xRange = ActiveDocument.Footnotes(countNum).Range
            s = s & vbCr & countNum & vbTab & xRange
        countNum = countNum + 1
    Loop
    Set doc = Documents.Add
    doc.Range.Text = s
    
End Sub

提前致谢。

标签: vbams-word

解决方案


找到了我的问题的答案。

我遇到了错误,因为页码超过了脚注编号。因此,迭代时出现了问题。

脚注长度为 ActiveDocument.Footnotes.Count

Sub SelectA11FootnoteTexts()
    Dim s As String
    Dim ftnt As Word.Footnotes
    Dim doc As Word.Document
    Dim xRange As Range
    Dim countNum As Integer
    Set xDoc = ActiveDocument
    footNotesNum = xDoc.Footnotes.Count
    countNum = 1

    Do Until countNum > footNotesNum
          Set xRange = xDoc.Footnotes(countNum).Range
            s = s & vbCr & countNum & vbTab & xRange
        countNum = countNum + 1
    Loop
    Set doc = Documents.Add
    doc.Range.Text = s
    
End Sub

推荐阅读