Results 1 to 3 of 3
  1. #1
    Star Lounger
    Join Date
    Feb 2003
    Annapolis, Maryland, USA
    Thanked 0 Times in 0 Posts

    tricky macro problem (2002)

    I've been trying to come up with a way to select a paragraph with a comment directed at a specific reviewer. Each comment begins with one of three reviewer's initials. When I'm done my edit, I'd like to automatically select all paragraphs that have comments directed at one of these reviewers, copy them, and paste them into a new document. If I can't do that, it would be almost as good to select all paragraphs that contain any comments.

    I've tried to figure this out myself, but I've gotten nowhere. Thanks for any suggestions.
    Michael Coleman
    BOMI International

  2. #2
    2 Star Lounger
    Join Date
    Jan 2004
    Mount Prospect, Illinois
    Thanked 0 Times in 0 Posts

    Re: tricky macro problem (2002)

    It's not that bad, but it's hard to figure out what properties to use. The Comment object's Scope property contains the range that a comment is attached to, and the Range property contains the text of the comment itself. Not intuitive.

    You can either search the collection of paragraphs for comments, and copy those, or search the collection of comments. The latter is sure to be faster. Here's an excerpt of what you're looking for. It only displays the relevant comments in a message box, but copying to another doc is not difficult:
    <pre>Public Sub grabcomments(whose As String)
    Dim oblather As Comment
    Dim r As Range
    ' Iterate over the comments collection
    For Each oblather In ActiveDocument.Comments
    ' Check for the target initials
    If Left(oblather.Range, Len(whose)) = whose Then
    ' Check the range to see if it's empty, and select the paragraph it's part of
    Set r = oblather.Scope
    If r.Start = r.End Then Set r = r.Paragraphs(1).Range
    ' Display the comment and the original text
    MsgBox oblather.Range.Text & vbCr & r.Text
    set r = nothing
    End If
    Next oblather
    End Sub

  3. #3
    3 Star Lounger
    Join Date
    Apr 2004
    Boston, Massachusetts, USA
    Thanked 0 Times in 0 Posts

    Re: tricky macro problem (2002)

    Hi Michael,

    The following prompts you to enter the intials of the reviewer to whom the comments are directed. If any are found, a new document is created, and all the paragraphs with comments to that reviewer are pasted in. This way (1) The paragraph formatting is retained and (2) If the comment reference spans multiple paragraphs, all are included.

    This assumes the first characters in the comment are the initials, but the case does not have to match.


    <pre>Sub CopyCommentParasByInitial()
    Dim sInitials As String
    Dim para As Paragraph
    Dim docComments As Document
    Dim docActive As Document
    Dim c As Comment

    sInitials = InputBox(prompt:="Enter initials of reviewer:")
    If Len(sInitials) = 0 Then Exit Sub

    Set docActive = ActiveDocument
    For Each c In docActive.Comments
    If UCase$(Left$(c.Range.Text, Len(sInitials))) = UCase$(sInitials) Then
    For Each para In c.Reference.Paragraphs
    If docComments Is Nothing Then
    Set docComments = Documents.Add
    End If
    docComments.Range(docComments.Range.End - 1).Paste
    Next para
    End If
    Next c
    End Sub

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts