The code is to get all comments from a docx file, get the page and line of each comment
Sub exportWordComments\_Click()
'Dim Cmt As Comment
Dim excelApp As Object
Dim xlsWbk, objWdApp As Object
Dim commentsArray
Dim rows, temp, i As Integer
Dim filename As String
'Dim myWDoc As Word.Document
'get file name
filename = Application.GetOpenFilename
If filename = "False" Then
Exit Sub
End If
Set objWdApp = CreateObject("word.application")
objWdApp.Visible = True '启动word应用程序
Set mywdoc = objWdApp.Documents.Open(filename)
rows = mywdoc.Comments.Count
ReDim commentsArray(1 To rows, 1 To 5)
For i = 1 To rows
temp = temp + 1
'page
\*\*commentsArray(temp, 1) = mywdoc.Comments(i).scope.Information(wdActiveEndPageNumber)\*\*
'line
\*\*commentsArray(temp, 2) = mywdoc.Comments(i).scope.Information(wdFirstCharacterLineNumber)\*\*
'批注引用内容
commentsArray(temp, 3) = mywdoc.Comments(i).Scope
'批注内容
commentsArray(temp, 4) = mywdoc.Comments(i).Range.Text
'作者
commentsArray(temp, 5) = mywdoc.Comments(i).Author
Next
Set excelApp = CreateObject("Excel.Application")
'打开批注表
Set xlsWbk = excelApp.Workbooks.Add
With xlsWbk.Sheets(1)
.Cells.Clear
.Range("A2").Resize(rows, 5) = commentsArray
.Range("A1") = "页码"
.Range("B1") = "行号"
.Range("C1") = "批注选中的原文字"
.Range("D1") = "批注内容"
.Range("E1") = "批注作者"
.Columns.AutoFit
End With
xlsWbk.SaveAs mywdoc.Path & Application.PathSeparator & "修订表.xlsx"
xlsWbk.Close
excelApp.Application.Quit
End Sub
I changed word file or information style , can not solve this problem