{"id":2379,"date":"2026-10-20T07:25:29","date_gmt":"2026-10-19T23:25:29","guid":{"rendered":"https:\/\/xlwings.net\/blog\/?p=2379"},"modified":"2026-03-29T10:05:09","modified_gmt":"2026-03-29T10:05:09","slug":"how-to-use-rangeclearnotes-in-the-xlwings-api-way","status":"publish","type":"post","link":"https:\/\/xlwings.net\/blog\/how-to-use-rangeclearnotes-in-the-xlwings-api-way\/","title":{"rendered":"How to use Range.ClearNotes in the xlwings API way"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">The <strong>ClearNotes<\/strong> member of the <strong>Range<\/strong> object in Excel is used to remove all cell notes (which are now officially called &#8220;comments&#8221; in modern Excel versions, but the older &#8220;notes&#8221; terminology persists in the object model for legacy reasons) from the specified range. In xlwings, this functionality is exposed through the <code>api<\/code> property, which provides direct access to the underlying Excel object model. This is particularly useful when you need to clean up annotations, comments, or notes from a dataset before performing analysis or redistribution, ensuring a clean slate.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Syntax and Parameters:<\/strong><br>In xlwings, you access the ClearNotes method via the <code>api<\/code> property of a Range object. The syntax is straightforward as the method does not take any parameters.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>range.api.ClearNotes()<\/code><\/pre>\n\n\n\n<ul class=\"wp-block-list\">\n<li><code>range<\/code>: This is an xlwings Range object representing the cells from which you want to remove notes.<\/li>\n\n\n\n<li><code>.api<\/code>: This property provides the native Excel VBA object model interface.<\/li>\n\n\n\n<li><code>.ClearNotes()<\/code>: The method call itself. It acts on the range and removes all notes.<\/li>\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Important Note:<\/strong> In Excel&#8217;s object model, &#8220;notes&#8221; refer to the legacy comment format. In Excel for Microsoft 365 and Excel 2021, the traditional &#8220;comments&#8221; have been replaced by threaded comments, but the <code>ClearNotes<\/code> method still removes the older style notes. For new threaded comments, you would typically use the <code>ClearComments<\/code> method. The <code>ClearNotes<\/code> method will not generate an error if there are no notes in the range; it will simply do nothing.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Code Examples:<\/strong><\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li><strong>Clearing notes from a specific range:<\/strong><br>This example removes all notes from cells A1 through C10 on the active sheet.<\/li>\n<\/ol>\n\n\n\n<pre class=\"wp-block-code\"><code>import xlwings as xw\n\n# Connect to the active Excel instance and workbook\napp = xw.apps.active\nwb = app.books.active\nsheet = wb.sheets.active\n\n# Define the target range\ntarget_range = sheet.range(\"A1:C10\")\n\n# Clear all notes from this range\ntarget_range.api.ClearNotes()<\/code><\/pre>\n\n\n\n<ol start=\"2\" class=\"wp-block-list\">\n<li><strong>Clearing notes from all used cells on a worksheet:<\/strong><br>This example is more comprehensive, clearing notes from every cell that has ever been used on the specified worksheet.<\/li>\n<\/ol>\n\n\n\n<pre class=\"wp-block-code\"><code>import xlwings as xw\n\nwb = xw.Book(\"Report.xlsx\")\nsheet = wb.sheets&#91;\"DataSheet\"]\n\n# Use the 'used_range' property to get all cells with content or formatting\nused_range = sheet.used_range\nused_range.api.ClearNotes()\n\n# Save the changes\nwb.save()<\/code><\/pre>\n\n\n\n<ol start=\"3\" class=\"wp-block-list\">\n<li><strong>Conditional clearing based on cell value:<\/strong><br>This example demonstrates a more advanced scenario where notes are cleared only from cells that meet a specific condition, such as containing a negative number.<\/li>\n<\/ol>\n\n\n\n<pre class=\"wp-block-code\"><code>import xlwings as xw\n\napp = xw.App(visible=False)\nwb = app.books.open(\"Financials.xlsx\")\nsheet = wb.sheets&#91;0]\n\n# Loop through a range, e.g., the first column\nfor cell in sheet.range(\"A1:A100\"):\n    # Check if the cell value is a number and less than zero\n    if isinstance(cell.value, (int, float)) and cell.value &lt; 0:\n        # Clear the note only for this specific cell\n        cell.api.ClearNotes()\n\nwb.save()\nwb.close()\napp.quit()<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\"><\/p>\n","protected":false},"excerpt":{"rendered":"<p>The **ClearNotes** member of the **Range** object in Excel is used to remove all cell notes (which a&#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-2379","post","type-post","status-publish","format-standard","hentry","category-xlwings-api-reference"],"_links":{"self":[{"href":"https:\/\/xlwings.net\/blog\/wp-json\/wp\/v2\/posts\/2379","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=2379"}],"version-history":[{"count":2,"href":"https:\/\/xlwings.net\/blog\/wp-json\/wp\/v2\/posts\/2379\/revisions"}],"predecessor-version":[{"id":3624,"href":"https:\/\/xlwings.net\/blog\/wp-json\/wp\/v2\/posts\/2379\/revisions\/3624"}],"wp:attachment":[{"href":"https:\/\/xlwings.net\/blog\/wp-json\/wp\/v2\/media?parent=2379"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/xlwings.net\/blog\/wp-json\/wp\/v2\/categories?post=2379"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/xlwings.net\/blog\/wp-json\/wp\/v2\/tags?post=2379"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}