How to get the content of a comment that has been clicked on ?

Ariel NORA 20 Reputation points
2025-11-24T10:11:05.99+00:00

Hello,

I am currently working on a Microsoft Add-In by using the Office js API and I need to retrieve the content of comments from a word document.

I have been able to find how to retrieve the content of the comment when clicking on the text attached to the comment (clicking on the green part of the image), but not when clicking directly on the comment itself outside the pages (red part of the image).User's image

It seems that using "await context.sync()" while clicking on the red part will give "GeneralException".

I have found out there is a function in the Preview build of Office js that seems to work for this exact scenario (onCommentSelected), but I wanted to know if anyone knew how to do it without using the preview build ?

Thank you

Microsoft 365 and Office | Development | Office JavaScript API
0 comments No comments
{count} votes

Answer accepted by question author
  1. Steven-N 14,835 Reputation points Microsoft External Staff Moderator
    2025-11-24T11:57:36.7733333+00:00

    Hi Ariel NORA

    Thank you for reaching out to Microsoft Q&A forum

    Based on my research about Office JavaScript API documentation I have found, there is currently no stable method to directly handle comment selection events in the sidebar (comment pane) without relying on preview APIs like onCommentSelected.

    That event, along with others such as onCommentDeselected, is specifically designed for detecting when a comment is selected or deselected, including in the pane, but remains in public preview as of late 2025. The stable API supports working with comments via classes like Word.Comment and Word.CommentCollection, including retrieving content through methods like getComments() on a Range object or loading properties such as contentRange on a specific comment. However, these don't include built-in events for pane-specific interactions.

    You can read here for more insight:

    Therefore, from my perspective view about this context, to handle this without preview APIs, you can try to redesign your add-in to rely on document-body selections by using Document.onSelectionChanged to detect when the user moves the cursor, then call context.document.getSelection().getComments() to load any comments attached to that selection.

    Link references: https://github.com/OfficeDev/office-js/issues/2563

    Additionally, if your deployment allows switch to the preview build (reference the beta CDN) and implement onCommentSelected for full pane support, which provides CommentEventArgs including the comment ID for direct content retrieval.

    Hope my answer will help you, for any further concern, kindly let me know in the comment section.


    If the answer is helpful, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".     

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    1 person found this answer helpful.
    0 comments No comments

1 additional answer

Sort by: Most helpful
  1. Stefan Blom 323.1K Reputation points MVP Volunteer Moderator
    2025-11-24T13:37:31.0566667+00:00

    If you click in the commented range on the document page, the (modern) comment moves closer to the page. It is a rather subtle change, but it does indicate that a comment is active. See the screen shot below.

    Of course, this won't work unless the comment is actually associated with a range in the document body.

    User's image

    0 comments No comments

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.