views:

248

answers:

1

I am trying to export of a Word document review comments. I want to export the sentence selection that was commented on followed by the comment.

Screen shot of the image: http://jspeaks.com/mswordcomment.png

I have found code to loop through the document comments, but I cannot figure out how to reference the sentence selection that the comment was related to.

The current logic is:

Sub ExportComments()
    Dim s As String
    Dim cmt As Word.Comment
    Dim doc As Word.Document

    For Each cmt In ActiveDocument.Comments
        s = s & cmt.Initial & cmt.Index & "," & cmt.Range.Text & vbCr
    Next

    Set doc = Documents.Add
    doc.Range.Text = s
End Sub

I tinkered with Selection.Range, however I cannot determine the proper object or property that contains the referenced sentence.

I would like to produce output like the follow (if we use the example in picture above):

Sentence: Here are more sentences that contain interesting facts - Comment: This is an interesting fact. Sentence: Here are more sentences that contain interesting facts. Here are more sentences that contain interesting facts. - Comment: This is a very interesting fact

+1  A: 

I found someone on RentACoder to solve this question. I decided to share it on StackOverflow for all those who need this solution. Benefit from it.

The key to the solution is: cmt.Scope.FormattedText

Here is the function revised:

Sub ExportComments()
    Dim s As String
    Dim cmt As Word.Comment
    Dim doc As Word.Document

    For Each cmt In ActiveDocument.Comments
        s = s & "Text: " & cmt.Scope.FormattedText & " -> "
        s = s & "Comments: " & cmt.Initial & cmt.Index & ":" & cmt.Range.Text & vbCr
    Next

    Set doc = Documents.Add
    doc.Range.Text = s
End Sub

If you want to contribute back to me for paying for the RentACoder solution then visit my site http://buyercommand.com . It is a more efficient interface for reviewing eBay listings, and anything you bid on will help me validate that product.

jspeaks
Great that you have a solution. You can go ahead and accept your own answer as the correct one (the checkmark).
Otaku