You are on page 1of 2

Sub exportComments()

' Exports comments from a MS Word document to Excel and associates them with the
heading paragraphs
' they are included in. Useful for outline numbered section, i.e. 3.2.1.5....
' Thanks to Graham Mayor, http://answers.microsoft.com/en-us/office/forum/office
_2007-customize/export-word-review-comments-in-excel/54818c46-b7d2-416c-a4e3-313
1ab68809c
' and Wade Tai, http://msdn.microsoft.com/en-us/library/aa140225(v=office.10).as
px
' Need to set a VBA reference to "Microsoft Excel 14.0 Object Library"
Dim
Dim
Dim
Dim
Dim
Dim
Dim
Dim

xlApp As Excel.Application
xlWB As Excel.Workbook
i As Integer, HeadingRow As Integer
objPara As Paragraph
objComment As Comment
strSection As String
strTemp
myRange As Range

Set xlApp = CreateObject("Excel.Application")


xlApp.Visible = True
Set xlWB = xlApp.Workbooks.Add 'create a new workbook
With xlWB.Worksheets(1)
' Create Heading
HeadingRow = 1
.Cells(HeadingRow, 1).Formula = "Comment"
.Cells(HeadingRow, 2).Formula = "Page"
.Cells(HeadingRow, 3).Formula = "Line"
.Cells(HeadingRow, 4).Formula = "Comment"
.Cells(HeadingRow, 5).Formula = "Reviewer"
.Cells(HeadingRow, 6).Formula = "Date"
strSection = "preamble" 'all sections before "1." will be labeled as "preamb
le"
strTemp = "preamble"
If ActiveDocument.Comments.Count = 0 Then
MsgBox ("No comments")
Exit Sub
End If
For i = 1 To ActiveDocument.Comments.Count
Set myRange = ActiveDocument.Comments(i).Scope
Set oComment = ActiveDocument.Comments(i) ''''new
Set oCommentRange = oComment.Scope.Paragraphs(1).Range '''mew
strSection = oCommentRange.Information(wdFirstCharacterLineNumber) 'Pare
ntLevel(myRange.Paragraphs(1)) ' find the section heading for this comment
'MsgBox strSection
.Cells(i + HeadingRow, 1).Formula = ActiveDocument.Comments(i).Index
.Cells(i + HeadingRow, 2).Formula = ActiveDocument.Comments(i).Reference
.Information(wdActiveEndAdjustedPageNumber)
.Cells(i + HeadingRow, 3).Value = strSection
.Cells(i + HeadingRow, 4).Formula = ActiveDocument.Comments(i).Range
.Cells(i + HeadingRow, 5).Formula = ActiveDocument.Comments(i).Initial
.Cells(i + HeadingRow, 6).Formula = Format(ActiveDocument.Comments(i).Da
te, "dd/MM/yyyy")
.Cells(i + HeadingRow, 7).Formula = ActiveDocument.Comments(i).Range.Lis
tFormat.ListString
Next i
End With

Set xlWB = Nothing


Set xlApp = Nothing
End Sub
Function ParentLevel(Para As Word.Paragraph) As String
'From Tony Jollans
' Finds the first outlined numbered paragraph above the given paragraph object
Dim ParaAbove As Word.Paragraph
Set ParaAbove = Para
sStyle = Para.Range.ParagraphStyle
sStyle = Left(sStyle, 4)
If sStyle = "Head" Then
GoTo Skip
End If
On Error GoTo 10
Do While ParaAbove.OutlineLevel = Para.OutlineLevel
Set ParaAbove = ParaAbove.Previous
Loop
Skip:
strTitle = ParaAbove.Range.Text
strTitle = Left(strTitle, Len(strTitle) - 1)
ParentLevel = ParaAbove.Range.ListFormat.ListString & " " & strTitle
GoTo 20
10
ParentLevel = " "

20
On Error GoTo 0
End Function

You might also like