VBA-提取评论标题

发布于 2025-01-10 13:23:12 字数 1209 浏览 0 评论 0原文

我想编写一个代码,其中 word 文档的每个注释都将被提取到 Excel 工作表中,并写入所属的章节/标题。

该代码实际上有效,但我不知道如何获取章节。它应该是章节的编号,如 1 或 1.1 等。 有人知道吗?

'set a reference to the Excel object library 

Dim xlApp As Excel.Application

Dim xlWB As Excel.Workbook
Dim i As Integer
Set xlApp = CreateObject("Excel.Application")
xlApp.Visible = True
Set xlWB = xlApp.Workbooks.Add ' create a new workbook
With xlWB.Worksheets(1)
        .Cells(1, 2).Formula = "author"
        .Cells(1, 3).Formula = "site"
        .Cells(1, 4).Formula = "comment"
        .Cells(1, 1).Formula = "date"
        .Cells(1, 5).Formula = "chapter"
        .Range("A1:E1").Font.Bold = True

For i = 1 To ActiveDocument.Comments.Count
    .Cells(i + 1, 2).Formula = ActiveDocument.Comments(i).Contact
    .Cells(i + 1, 3).Formula = ActiveDocument.Comments(i).Scope.Paragraphs(1).Range.Information(wdActiveEndPageNumber)
    .Cells(i + 1, 4).Formula = ActiveDocument.Comments(i).Range
    .Cells(i + 1, 1).Formula = Format(ActiveDocument.Comments(i).Date, "dd/MM/yyyy")
    .Cells(i + 1, 5).Formula = ???????? (Code to show the heading)
Next i

    .Range("A1:D1").AutoFilter
End With
Set xlWB = Nothing
Set xlApp = Nothing
End Sub

I want to write a code, where every comment of a word-document will be extracted into an excel sheet AND the belonging chapter/heading it is written in.

The Code actually works but I have no clue how to get the chapter. It should be the number of the chapter like 1 or 1.1 and so on.
Does anybody has a clue?

'set a reference to the Excel object library 

Dim xlApp As Excel.Application

Dim xlWB As Excel.Workbook
Dim i As Integer
Set xlApp = CreateObject("Excel.Application")
xlApp.Visible = True
Set xlWB = xlApp.Workbooks.Add ' create a new workbook
With xlWB.Worksheets(1)
        .Cells(1, 2).Formula = "author"
        .Cells(1, 3).Formula = "site"
        .Cells(1, 4).Formula = "comment"
        .Cells(1, 1).Formula = "date"
        .Cells(1, 5).Formula = "chapter"
        .Range("A1:E1").Font.Bold = True

For i = 1 To ActiveDocument.Comments.Count
    .Cells(i + 1, 2).Formula = ActiveDocument.Comments(i).Contact
    .Cells(i + 1, 3).Formula = ActiveDocument.Comments(i).Scope.Paragraphs(1).Range.Information(wdActiveEndPageNumber)
    .Cells(i + 1, 4).Formula = ActiveDocument.Comments(i).Range
    .Cells(i + 1, 1).Formula = Format(ActiveDocument.Comments(i).Date, "dd/MM/yyyy")
    .Cells(i + 1, 5).Formula = ???????? (Code to show the heading)
Next i

    .Range("A1:D1").AutoFilter
End With
Set xlWB = Nothing
Set xlApp = Nothing
End Sub

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文