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?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.


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:
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


Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Bryce BassettFreelance VBA programmerAuthor Commented:
Suggested answer did not solve the issue.  Found the answer myself via Google search.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.