A family of Microsoft word processing software products for creating web, email, and print documents.
Try:
Sub ExportComments()
Dim StrCmt As String, StrTmp As String, i As Long, j As Long, xlApp As Object, xlWkBk As Object
StrCmt = "Page,Author,Date & Time,H.Lvl,Commented Text,Comment,Reviewer,Resolution,Date Resolved,Edit Doc,Edit By,Edit Date"
StrCmt = Replace(StrCmt, ",", vbTab)
With ActiveDocument
' Process the Comments
For i = 1 To .Comments.Count
With .Comments(i)
StrCmt = StrCmt & vbCr & .Reference.Information(wdActiveEndAdjustedPageNumber) & _
vbTab & .Author & vbTab & .Date & vbTab
With .Scope
If InStr(.Paragraphs(1).Style, "Heading") = 1 Then
StrCmt = StrCmt & .Paragraphs(1).Range.ListFormat.ListString & vbTab
Else
StrCmt = StrCmt & ParentLevel(.Paragraphs(1)) & vbTab
End If
With .Duplicate
.End = .End - 1
StrCmt = StrCmt & Replace(Replace(.Text, vbTab, "<TAB>"), vbCr, "<P>") & vbTab
End With
End With
With .Range.Duplicate
.End = .End - 1
StrCmt = StrCmt & Replace(Replace(.Text, vbTab, "<TAB>"), vbCr, "<P>")
End With
End With
Next
StrTmp = .Name
End With
' Test whether Excel is already running.
On Error Resume Next
Set xlApp = GetObject(, "Excel.Application")
'Start Excel if it isn't running
If xlApp Is Nothing Then
Set xlApp = CreateObject("Excel.Application")
If xlApp Is Nothing Then
MsgBox "Can't start Excel.", vbExclamation
Exit Sub
End If
End If
On Error GoTo 0
With xlApp
Set xlWkBk = .Workbooks.Add
' Update the workbook.
With xlWkBk.Worksheets(1)
.Name = StrTmp
.Columns("D").NumberFormat = "@"
For i = 0 To UBound(Split(StrCmt, vbCr))
StrTmp = Split(StrCmt, vbCr)(i)
For j = 0 To UBound(Split(StrTmp, vbTab))
.Cells(i + 1, j + 1).Value = Split(StrTmp, vbTab)(j)
Next
Next
.Columns("A:L").AutoFit
.Columns("E:F").ColumnWidth = 25
End With
' Tell the user we're done.
MsgBox "Workbook updates finished.", vbOKOnly
' Switch to the Excel workbook
.Visible = True
End With
' Release object memory
Set xlWkBk = Nothing: Set xlApp = Nothing
End Sub
Function ParentLevel(Para As Paragraph) As String
Dim ParaHd As Paragraph, StrTmp As String
Set ParaHd = Para
Do While ParaHd.OutlineLevel = Para.OutlineLevel
Set ParaHd = ParaHd.Previous
Loop
ParentLevel = ParaHd.Range.ListFormat.ListString
End Function
Rather than taking up extra columns for every possible heading level (there could be as many as 9 in a Word document), those data are all output to a single column. The levels should remain quite apparent, there.