Hi,
I can't seem to extract the page and line numbers from a Word file comment into excel.
The code I wrote currently does the following:
Checks if there are any open Word files and allows the user to select which file they wish to extract comments from. Once the selection is made, the comments are pulled into the excel file. The parameters I'm looking for are:
Page number
Line number
Scope
Comment Text
Author
All of this is working except for the page number and line number. It looks to me like I'm using a very similar solution as I've found online. Could someone help?
Sub pullcommentsfrom()
Dim OpenDocName As String
Dim Wd As Object
Dim docCount
Dim nCount
Dim n As Long
Dim Title As String
Title = "Extract Comments"
' Check if a Word file is open
On Error Resume Next
Set Wd = GetObject(, "Word.Application")
If Wd Is Nothing Then
MsgBox "No file is open", vbCritical
Exit Sub
End If
' Select which open Word file to use
For docCount = 1 To Wd.Documents.Count
OpenDocName = Wd.Documents(docCount).Name
If MsgBox("Extract comments from " + OpenDocName + " below selected cell?", _
vbYesNo + vbQuestion, Title) = vbYes Then
GoTo DocSelected
End If
Next docCount
MsgBox "No file selected", vbCritical
Exit Sub
DocSelected:
' Check if document has any comments
nCount = Wd.Documents(docCount).Comments.Count
If nCount = 0 Then
MsgBox "The selected document contains no comments.", vbOKOnly, Title
Exit Sub
End If
'Pull all comments into Excell file
For n = 1 To nCount
ActiveSheet.Cells(ActiveCell.Row, 1).Select
'Page number
ActiveCell.Value = Wd.Documents(docCount).Comments(n).Scope.Information(wdActiveEndAdjustedPageNumber)
ActiveCell.Offset(0, 1).Select
'Line number
ActiveCell.Value = Wd.Documents(docCount).Comments(n).Scope.Information(wdFirstCharacterLineNumber)
ActiveCell.Offset(0, 1).Select
'The text marked by the comment
ActiveCell.Value = Wd.Documents(docCount).Comments(n).Scope
ActiveCell.Offset(0, 1).Select
'The comment itself
ActiveCell.Value = Wd.Documents(docCount).Comments(n).Range.Text
ActiveCell.Offset(0, 1).Select
'The comment author
ActiveCell.Value = Wd.Documents(docCount).Comments(n).Author
ActiveCell.Offset(1, 0).Select
Next n
ActiveSheet.Cells(ActiveCell.Row, 1).Select
End Sub
Bookmarks