Results 1 to 4 of 4
  1. #1
    Lounger
    Join Date
    Apr 2005
    Location
    Silver Spring, Maryland, USA
    Posts
    36
    Thanks
    0
    Thanked 1 Time in 1 Post

    Change comment scope (Word 2003)

    I'm looking for a way to change the scope of an existing comment using a macro. I've fiddled with the scope property of the comment, but it seems not to respond to setRange or changing the start and end of the range.

    Am I overlooking something?

    Or should I fall back on something that makes the user select the comment, then select the new scope, and then deletes the old comment and makes a new comment with the old text and the new scope?

    Thanks,

    Jessica

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Change comment scope (Word 2003)

    According to the Object Browser (F2), Scope is a read-only property, so you cannot change it once the comment has been created.
    So your plan of deleting the existing comment and creating a new one is the best you can do.

  3. #3
    Lounger
    Join Date
    Apr 2005
    Location
    Silver Spring, Maryland, USA
    Posts
    36
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: Change comment scope (Word 2003)

    Thanks. I always forget about the Object Browser.

    Recreating the comment resets the date to the present one, of course. I've got the alternate method working. They have to select the new comment reference first, but it does check to make sure it is a usable one.

    - Jessica

  4. #4
    Super Moderator jscher2000's Avatar
    Join Date
    Feb 2001
    Location
    Silicon Valley, USA
    Posts
    23,112
    Thanks
    5
    Thanked 93 Times in 89 Posts

    Re: Change comment scope (Word 2003)

    This is a "proof of concept" for inserting text to a comment scope without changing any properties of the comment. It uses the .Scope property to create a fresh range, which of course is read-write. I'm sure you can imagine many further developments from here. And also it has no error checking, so it's not ready for deployment.

    Note: This tests on the first comment in the document, and requires that comment to have a scope consisting of at least two characters. With fewer than two characters, the code destroys the comment.

    <code>Sub TEST_InsertToCommentScope()
    ' Insert text on clipboard at end of first comment scope
    InsertToCommentScope ActiveDocument.Comments(1), True
    ' Insert a string to the start of the first comment scope
    InsertToCommentScope ActiveDocument.Comments(1), False, 1, "As I was saying... "
    End Sub

    Sub InsertToCommentScope(comTarget As Word.Comment, blnPaste As Boolean, _
    Optional intInsertPosition As Integer = 0, _
    Optional strTextToInsert As String = vbNullString)
    ' Set up ranges
    Dim rngScope As Word.Range, rngIP As Word.Range, blnPreviousChar As Boolean, _
    rngChar As Word.Range, strTemp As String
    Set rngScope = ActiveDocument.Range(comTarget.Scope.Start, comTarget.Scope.End)
    If intInsertPosition = 0 Or intInsertPosition > rngScope.Characters.Count Then
    ' Add new content to the end of the range (subtract 1 and move the other character later)
    Set rngIP = ActiveDocument.Range(rngScope.End - 1, rngScope.End - 1)
    blnPreviousChar = False
    Else
    ' Add new content at the specified point (add 1 and move the other character later)
    Set rngIP = ActiveDocument.Range(rngScope.Start + 1, rngScope.Start + 1)
    blnPreviousChar = True
    End If
    If blnPaste Then
    rngIP.Paste
    Else
    rngIP.InsertAfter strTextToInsert
    End If
    ' Move the dislocated character
    If blnPreviousChar Then
    Set rngChar = ActiveDocument.Range(rngIP.Start - 1, rngIP.Start)
    strTemp = rngChar.Text
    rngChar.Delete
    Set rngChar = Nothing
    rngIP.InsertAfter strTemp
    Else
    Set rngChar = ActiveDocument.Range(rngIP.End, rngIP.End + 1)
    strTemp = rngChar.Text
    rngChar.Delete
    Set rngChar = Nothing
    rngIP.InsertBefore strTemp
    End If
    ' Clean up objects
    Set rngIP = Nothing
    Set rngScope = Nothing
    End Sub</code>

Posting Permissions

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