VBA: Why does adding a comment programmatically in Word open the Comments pane?

I'm using VBA code in Word 2010/2016 to add a comment to the selection range in Word.  Works fine, but it opens the Comments pane at the bottom of the screen and positions my insertion point down in that pane, which I don't want.  I just want my insertion point to be inside the newly added comment bubble on the right margin, the same as when I manually add a comment.

I tried newcomment.range.select or newcomment.edit, but both still put me down in the bottom pane.  

So I need to understand how to prevent the Comment pane from showing altogether, or a way to close it once it does.

Appreciate any help.
Bryce BassettFreelance VBA programmerAsked:
Who is Participating?
Bryce BassettConnect With a Mentor Freelance VBA programmerAuthor Commented:
Thanks for the suggestion, but that did not work for me.  

I found my answer here:  on Stack Overflow

Here is the code I ended up with.  It adds a comment at the insertion point, and if the user has text selected when they run the macro, it also copies that text into the comment for further editing.  

Sub addcomment(control As IRibbonControl)

Dim newcom As Comment
Dim somethingtopaste As Boolean

'add comment at insertion point.  If text is selected, copy that to comment
If Selection.Start <> Selection.End Then
    somethingtopaste = True
    Selection.Collapse direction:=wdCollapseEnd
    Selection.MoveRight unit:=wdCharacter, Count:=1
End If
Selection.MoveLeft unit:=wdCharacter, Count:=1, Extend:=True

'add comment
Set newcom = ActiveDocument.Comments.Add(Selection.Range)

'Close the Comments pane if it's visible
If WordBasic.ViewAnnotations = -1 Then
   WordBasic.ViewAnnotations 0
End If

'edit the comment bubble and (optional) paste in highlighted text
If somethingtopaste = True Then Selection.Paste

End Sub

Open in new window


in Wd 2016 pls try
    Dim wrdRevisionsFilter As RevisionsFilter
    Set wrdRevisionsFilter = ActiveDocument.ActiveWindow.View.RevisionsFilter
    wrdRevisionsFilter.Markup = wdRevisionsMarkupSimple

Open in new window

before commenting

Not tested

Bryce BassettFreelance VBA programmerAuthor Commented:
Suggested answer did not solve the issue.  Found the answer myself via Google search.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.