How to Retrieve Word Comment Content From a Comments Pane Selection
Question details
The user needs to retrieve content from a specific Word comment when it is selected in the comments pane using the Office JavaScript API.

- Product
- Microsoft Word (Office JS API)
- Device & OS
- not provided
- Scenario
- Developing a Word add-in that interacts with user comments and tracks selections within the comments pane.
- Observed behavior
- The stable Office JavaScript API does not currently expose an event for selecting a comment directly in the comments pane or clicking a reply box.
Ensure your development environment references the latest version of the Office JavaScript API and verify whether your project requirements allow the use of preview APIs.
Use Document-Body Selection Events (Stable API)
Since the stable API lacks direct pane-selection events, use this workaround to retrieve comments by capturing text selection in the document body.
The stable Office JavaScript API supports comment objects and collections but does not expose an event for selecting a comment directly in the comments pane. The recommended alternative is to capture the user's selection within the document itself.
Add an event handler for the `Document.onSelectionChanged` event in your add-in code to detect when a user clicks inside a commented range.
Inside the event handler, call `context.document.getSelection()` to access the currently selected text range.
Chain the `.getComments()` method to the selected range to retrieve the collection of comments attached to that specific section of the document.
Load the required comment properties and call `context.sync()` to execute the batch and process the retrieved comment content.
Use the onCommentSelected Event (Preview API)
Use this approach if you are developing in an environment where preview APIs are acceptable for direct comments-pane interactions.
Use WPS Office for Seamless Document Management
If you are encountering API limitations in Microsoft Word or simply need a highly efficient environment for processing documents and comments, consider WPS Office. It provides robust compatibility with Office formats, a familiar interface, and excellent tools for managing document reviews without the heavy overhead.
- 1. Download WPS Office: Visit the official WPS website and download the free installation package tailored for your operating system.
- 2. Open Your Word Documents: Launch WPS Writer and open your existing .docx files. Your formats, margins, and comments will load seamlessly.
- 3. Manage Comments Effortlessly: Navigate to the Review tab to easily read, reply to, and manage all document comments using built-in, highly optimized tools.

Frequently Asked Questions
Can I capture a click event specifically for a comment's reply box using the Word API?
Currently, there is no stable event specifically designed for capturing a click on a comment's reply box. You must rely on alternative methods, such as document body selection events, to interact with comments programmatically.
How can I get the ID of a comment selected directly in the comments pane?
To get the selected comment ID directly from the comments pane, you must use the preview API event `onCommentSelected`. Note that this feature is not yet available in the stable API release.
Why does the modern comment move closer to the page when I click the text?
When you click within a commented text range in the document body, the modern comment visually moves closer to the page to indicate that it is active. This UI behavior only functions if the comment is explicitly associated with a range in the document body.




