{"id":2068,"date":"2026-05-17T15:38:35","date_gmt":"2026-05-17T07:38:35","guid":{"rendered":"https:\/\/xlwings.net\/blog\/?p=2068"},"modified":"2026-03-28T06:04:07","modified_gmt":"2026-03-28T06:04:07","slug":"how-to-use-applicationcutcopymode-in-the-xlwings-api-way","status":"publish","type":"post","link":"https:\/\/xlwings.net\/blog\/how-to-use-applicationcutcopymode-in-the-xlwings-api-way\/","title":{"rendered":"How to use Application.CutCopyMode in the xlwings API way"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">The Application.CutCopyMode property in Excel VBA is a property of the Application object that returns or sets the status of the Cut or Copy mode. This property is useful for programmatically determining if a cut or copy operation is currently active, or to cancel such an operation. In xlwings, this property is accessed through the <code>api<\/code> property of the App object, which provides direct access to the underlying Excel object model. Understanding this property is essential for automating tasks that involve clipboard operations, ensuring that your macros run without interference from pending cut\/copy actions.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Functionality:<\/strong><br>The primary function of the CutCopyMode property is to manage the state of cut and copy operations within Excel. It can have three possible values:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>False (or 0):<\/strong> Indicates that no cut or copy operation is currently in progress.<\/li>\n\n\n\n<li><strong>True (or 1):<\/strong> Indicates that a copy operation is active. The source range is highlighted with a moving border.<\/li>\n\n\n\n<li><strong>xlCut (or 2):<\/strong> Indicates that a cut operation is active. The source range is also highlighted.<\/li>\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\">By reading this property, your script can check for an active operation before performing actions that might conflict, such as pasting or clearing the clipboard. Setting this property to <code>False<\/code> is the programmatic equivalent of pressing the ESC key, which cancels the moving border and clears the clipboard state.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Syntax in xlwings:<\/strong><br>In xlwings, you interact with this property via the Excel Application object&#8217;s COM interface.<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>To Get the current mode:<\/strong><br><code>current_mode = xw.apps[&lt;app_index>].api.CutCopyMode<\/code><br>This returns an integer corresponding to the current state.<\/li>\n\n\n\n<li><strong>To Set the mode (typically to cancel):<\/strong><br><code>xw.apps[&lt;app_index>].api.CutCopyMode = False<\/code><\/li>\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Parameter &amp; Return Values:<\/strong><br>The property is read\/write. Its value can be set or returned as a <code>Long<\/code> integer or a <code>Boolean<\/code>. The standard values are:<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table class=\"has-fixed-layout\"><thead><tr><th class=\"has-text-align-left\" data-align=\"left\">Value<\/th><th class=\"has-text-align-left\" data-align=\"left\">Constant (VBA)<\/th><th class=\"has-text-align-left\" data-align=\"left\">Description<\/th><\/tr><\/thead><tbody><tr><td class=\"has-text-align-left\" data-align=\"left\">0<\/td><td class=\"has-text-align-left\" data-align=\"left\"><code>False<\/code><\/td><td class=\"has-text-align-left\" data-align=\"left\">No cut or copy mode is active.<\/td><\/tr><tr><td class=\"has-text-align-left\" data-align=\"left\">1<\/td><td class=\"has-text-align-left\" data-align=\"left\"><code>True<\/code><\/td><td class=\"has-text-align-left\" data-align=\"left\">Copy mode is active.<\/td><\/tr><tr><td class=\"has-text-align-left\" data-align=\"left\">2<\/td><td class=\"has-text-align-left\" data-align=\"left\"><code>xlCut<\/code><\/td><td class=\"has-text-align-left\" data-align=\"left\">Cut mode is active.<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">When setting the property, only <code>False<\/code> (0) is typically used to cancel the mode. Attempting to set it to <code>True<\/code> or <code>xlCut<\/code> does not initiate a new cut\/copy operation.<\/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>Checking and Reporting the Current Mode:<\/strong><br>This example checks the status and prints a descriptive message.<\/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\napp = xw.apps.active\n\n# Get the current CutCopyMode\nmode = app.api.CutCopyMode\n\nif mode == 0:\n    print(\"No cut or copy operation is active.\")\nelif mode == 1:\n    print(\"A copy operation is in progress.\")\nelif mode == 2:\n    print(\"A cut operation is in progress.\")\nelse:\n    print(f\"Unknown mode value: {mode}\")<\/code><\/pre>\n\n\n\n<ol start=\"2\" class=\"wp-block-list\">\n<li><strong>Cancelling an Active Cut\/Copy Operation:<\/strong><br>This is a common practice to ensure a clean state before executing other operations.<\/li>\n<\/ol>\n\n\n\n<pre class=\"wp-block-code\"><code>import xlwings as xw\n\napp = xw.apps.active\n\n# Check if a cut\/copy mode is active\nif app.api.CutCopyMode:\n    print(\"Cancelling the active cut\/copy mode.\")\n    app.api.CutCopyMode = False # Equivalent to pressing ESC\n\n# Now it's safe to proceed, e.g., with a paste operation\n# app.api.Selection.PasteSpecial() # Example follow-up action<\/code><\/pre>\n\n\n\n<ol start=\"3\" class=\"wp-block-list\">\n<li><strong>Integrating into a Larger Workflow:<\/strong><br>This example copies a range, performs a check, and then cancels the mode.<\/li>\n<\/ol>\n\n\n\n<pre class=\"wp-block-code\"><code>import xlwings as xw\n\napp = xw.apps.active\nwb = app.books.active\nsheet = wb.sheets&#91;0]\n\n# Perform a copy operation (this activates Copy mode)\nsheet.range(\"A1:B2\").copy()\n\n# Verify the mode was activated\nif app.api.CutCopyMode == 1:\n    print(\"Range copied successfully. Copy mode is active.\")\n\n# ... Perform other tasks ...\n\n# Cancel the copy mode explicitly when done\napp.api.CutCopyMode = False\nprint(\"Copy mode cleared.\")<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\"><\/p>\n","protected":false},"excerpt":{"rendered":"<p>The Application.CutCopyMode property in Excel VBA is a property of the Application object that retur&#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-2068","post","type-post","status-publish","format-standard","hentry","category-xlwings-api-reference"],"_links":{"self":[{"href":"https:\/\/xlwings.net\/blog\/wp-json\/wp\/v2\/posts\/2068","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=2068"}],"version-history":[{"count":1,"href":"https:\/\/xlwings.net\/blog\/wp-json\/wp\/v2\/posts\/2068\/revisions"}],"predecessor-version":[{"id":3164,"href":"https:\/\/xlwings.net\/blog\/wp-json\/wp\/v2\/posts\/2068\/revisions\/3164"}],"wp:attachment":[{"href":"https:\/\/xlwings.net\/blog\/wp-json\/wp\/v2\/media?parent=2068"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/xlwings.net\/blog\/wp-json\/wp\/v2\/categories?post=2068"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/xlwings.net\/blog\/wp-json\/wp\/v2\/tags?post=2068"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}