{"id":2360,"date":"2026-10-10T16:31:36","date_gmt":"2026-10-10T08:31:36","guid":{"rendered":"https:\/\/xlwings.net\/blog\/?p=2360"},"modified":"2026-03-29T09:53:45","modified_gmt":"2026-03-29T09:53:45","slug":"how-to-use-rangeaddcommentthreaded-in-the-xlwings-api-way","status":"publish","type":"post","link":"https:\/\/xlwings.net\/blog\/how-to-use-rangeaddcommentthreaded-in-the-xlwings-api-way\/","title":{"rendered":"How to use Range.AddCommentThreaded in the xlwings API way"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">The <strong>AddCommentThreaded<\/strong> member of the <strong>Range<\/strong> object in the Excel object model enables the creation of a modern, threaded comment (introduced in Microsoft 365) within a specified cell or range. Unlike traditional notes or legacy comments, threaded comments support conversational replies, mentions (@), and are stored separately, making them ideal for collaborative discussions directly within a spreadsheet. In xlwings, this functionality is exposed through the <code>api<\/code> property, which provides direct access to the underlying Excel object model, allowing precise control over comment creation and properties.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Syntax in xlwings:<\/strong><br><code>range.api.AddCommentThreaded(Text)<\/code><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>range<\/strong>: An xlwings Range object representing the target cell or range (e.g., <code>sheet.range('A1')<\/code>).<\/li>\n\n\n\n<li><strong>.api<\/strong>: Accesses the native Excel VBA object model.<\/li>\n\n\n\n<li><strong>Text<\/strong> (<em>optional<\/em>): A string specifying the initial text of the comment thread. If omitted, an empty comment is created.<\/li>\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\">This method returns a <strong>CommentThreaded<\/strong> object, which can be further manipulated\u2014for instance, to add replies, edit text, or resolve the thread. Key properties of the returned object include <code>Text<\/code> (for the initial comment), <code>Author<\/code> (the creator&#8217;s name), and <code>Replies<\/code> (a collection of reply objects).<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Example Usage with xlwings:<\/strong><\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li><strong>Creating a Basic Threaded Comment:<\/strong><\/li>\n<\/ol>\n\n\n\n<pre class=\"wp-block-code\"><code>import xlwings as xw\n\n# Connect to the active workbook and sheet\nwb = xw.books.active\nsheet = wb.sheets&#91;'Sheet1']\n\n# Add a threaded comment to cell B5\ntarget_cell = sheet.range('B5')\nnew_thread = target_cell.api.AddCommentThreaded(\"Initial review: Please verify these figures by EOD.\")<\/code><\/pre>\n\n\n\n<ol start=\"2\" class=\"wp-block-list\">\n<li><strong>Adding a Comment with a Mention and Retrieving Properties:<\/strong><\/li>\n<\/ol>\n\n\n\n<pre class=\"wp-block-code\"><code># Add a comment with a mention (using the @ symbol to tag a collaborator)\nthread = sheet.range('C10').api.AddCommentThreaded(\"@Alex, can you provide the Q3 data here?\")\n\n# Access properties of the new threaded comment\nprint(f\"Author: {thread.Author}\")\nprint(f\"Text: {thread.Text}\")\nprint(f\"Date\/Time: {thread.Date}\")\n\n# Add a reply to the thread\nthread.Replies.Add(\"I'll upload the file by 3 PM today.\")<\/code><\/pre>\n\n\n\n<ol start=\"3\" class=\"wp-block-list\">\n<li><strong>Handling an Existing Comment Thread:<\/strong><br>If a cell already contains a threaded comment, using <code>AddCommentThreaded<\/code> will raise an error. To avoid this, check for existing comments first:<\/li>\n<\/ol>\n\n\n\n<pre class=\"wp-block-code\"><code>cell = sheet.range('D2')\nif cell.api.CommentThreaded is None:\n    cell.api.AddCommentThreaded(\"New discussion thread.\")\nelse:\n    print(\"A threaded comment already exists in this cell.\")<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\"><\/p>\n","protected":false},"excerpt":{"rendered":"<p>The **AddCommentThreaded** member of the **Range** object in the Excel object model enables the crea&#8230;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[25],"tags":[],"class_list":["post-2360","post","type-post","status-publish","format-standard","hentry","category-xlwings-api-reference"],"_links":{"self":[{"href":"https:\/\/xlwings.net\/blog\/wp-json\/wp\/v2\/posts\/2360","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/xlwings.net\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/xlwings.net\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/xlwings.net\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/xlwings.net\/blog\/wp-json\/wp\/v2\/comments?post=2360"}],"version-history":[{"count":2,"href":"https:\/\/xlwings.net\/blog\/wp-json\/wp\/v2\/posts\/2360\/revisions"}],"predecessor-version":[{"id":3598,"href":"https:\/\/xlwings.net\/blog\/wp-json\/wp\/v2\/posts\/2360\/revisions\/3598"}],"wp:attachment":[{"href":"https:\/\/xlwings.net\/blog\/wp-json\/wp\/v2\/media?parent=2360"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/xlwings.net\/blog\/wp-json\/wp\/v2\/categories?post=2360"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/xlwings.net\/blog\/wp-json\/wp\/v2\/tags?post=2360"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}