VBA-提取评论标题
我想编写一个代码,其中 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论