logo
search
Office Settings & Configuration

How to Retrieve Word Comment Content From a Comments Pane Selection

Amos GikundaAmos Gikunda Sep 29, 2026 868 views

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.

How to Retrieve Word Comment Content From a Comments Pane Selection
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.
Before you start

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.

Solution 1Recommended

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.

1
Subscribe to Selection Events

Add an event handler for the `Document.onSelectionChanged` event in your add-in code to detect when a user clicks inside a commented range.

2
Retrieve the Selected Range

Inside the event handler, call `context.document.getSelection()` to access the currently selected text range.

3
Fetch Associated Comments

Chain the `.getComments()` method to the selected range to retrieve the collection of comments attached to that specific section of the document.

4
Sync the Context

Load the required comment properties and call `context.sync()` to execute the batch and process the retrieved comment content.

Visual Indicator of Active Comments: When a user clicks within the commented range on the document page, the modern comment moves closer to the page, indicating that it is active. This only works when the comment is associated with a range in the document body.
Free Microsoft Office alternative

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. 1. Download WPS Office: Visit the official WPS website and download the free installation package tailored for your operating system.
  2. 2. Open Your Word Documents: Launch WPS Writer and open your existing .docx files. Your formats, margins, and comments will load seamlessly.
  3. 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.
Seamlessly compatible with Microsoft Word (.docx) formatsFree and lightweight Microsoft Office alternativeFamiliar user interface for effortless migrationRobust built-in support for reviewing, commenting, and tracking changes
microsoft office alternative - wps office

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.