{"id":2065,"date":"2026-05-16T07:37:03","date_gmt":"2026-05-15T23:37:03","guid":{"rendered":"https:\/\/xlwings.net\/blog\/?p=2065"},"modified":"2026-03-28T06:02:00","modified_gmt":"2026-03-28T06:02:00","slug":"how-to-use-applicationcursor-in-the-xlwings-api-way","status":"publish","type":"post","link":"https:\/\/xlwings.net\/blog\/how-to-use-applicationcursor-in-the-xlwings-api-way\/","title":{"rendered":"How to use Application.Cursor in the xlwings API way"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">In the Excel object model, the <code>Application.Cursor<\/code> property is a member of the top-level <code>Application<\/code> object, which represents the entire Excel application. This property controls the visual appearance of the mouse cursor (pointer) in Excel. It is particularly useful in automation scenarios where you want to provide visual feedback to users, such as indicating that a long-running operation is in progress. By changing the cursor, you can enhance the user experience by signaling that the application is busy or that a specific action is required.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Functionality:<\/strong><br>The <code>Application.Cursor<\/code> property allows you to get or set the mouse cursor shape displayed in Excel. It can be used to change the cursor to standard shapes like an arrow, an I-beam for text selection, or a wait cursor (e.g., an hourglass or spinning wheel) during lengthy operations. This helps in making automated processes more user-friendly by visually communicating the application&#8217;s state.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Syntax:<\/strong><br>In xlwings, you can access the <code>Application.Cursor<\/code> property through the <code>app<\/code> object, which represents the Excel application. The property is used to get or set the cursor type. The syntax is as follows:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>To get the current cursor: <code>current_cursor = app.api.Cursor<\/code><\/li>\n\n\n\n<li>To set the cursor to a new value: <code>app.api.Cursor = cursor_value<\/code><\/li>\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\">Here, <code>app<\/code> is an instance of the xlwings <code>App<\/code> class, typically created with <code>xw.App()<\/code> or accessed via <code>xw.apps<\/code>. The <code>api<\/code> attribute provides direct access to the underlying Excel object model. The <code>cursor_value<\/code> is an integer or enumeration constant that specifies the cursor shape. In Excel VBA, these values are defined by the <code>XlMousePointer<\/code> enumeration. Common values include:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><code>xlDefault<\/code> (or 0): The default cursor (usually an arrow).<\/li>\n\n\n\n<li><code>xlWait<\/code> (or 1): A wait cursor (e.g., hourglass), indicating that Excel is busy.<\/li>\n\n\n\n<li><code>xlIBeam<\/code> (or 3): An I-beam cursor, used for text selection.<\/li>\n\n\n\n<li><code>xlNorthwestArrow<\/code> (or 2): A northwest arrow cursor.<\/li>\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\">To use these in xlwings, you can define constants or use the integer values directly. For example, <code>xlWait<\/code> corresponds to the integer 1.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Example:<\/strong><br>Below is an xlwings code example that demonstrates how to use the <code>Application.Cursor<\/code> property to change the mouse cursor during a time-consuming operation, such as processing data in a worksheet. This example shows setting the cursor to a wait state, performing a task, and then resetting it to the default.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>import xlwings as xw\nimport time\n\n# Connect to the active Excel application or start a new one\napp = xw.apps.active if xw.apps.active else xw.App()\n\n# Set the cursor to wait (hourglass) to indicate busy state\napp.api.Cursor = 1 # Using integer value for xlWait\nprint(\"Cursor set to wait state. Processing data...\")\n\n# Simulate a long-running task, e.g., iterating through cells\ntry:\n    # Access the active workbook and worksheet\n    wb = app.books.active\n    ws = wb.sheets.active\n\n    # Example operation: sum values in a range (this could be any intensive task)\ntotal = 0\n    for cell in ws.range(\"A1:A10\"): # Process a range of cells\n        if cell.value is not None:\n            total += cell.value\n            time.sleep(0.1) # Simulate delay for demonstration\n\n            print(f\"Total sum from A1:A10 is: {total}\")\n\nfinally:\n    # Always reset the cursor to default after the operation\n    app.api.Cursor = 0 # Using integer value for xlDefault\n    print(\"Cursor reset to default state.\")\n\n# Optional: Close the app if it was started in this script\n# app.quit()<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\"><\/p>\n","protected":false},"excerpt":{"rendered":"<p>In the Excel object model, the `Application.Cursor` property is a member of the top-level `Applicati&#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-2065","post","type-post","status-publish","format-standard","hentry","category-xlwings-api-reference"],"_links":{"self":[{"href":"https:\/\/xlwings.net\/blog\/wp-json\/wp\/v2\/posts\/2065","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=2065"}],"version-history":[{"count":2,"href":"https:\/\/xlwings.net\/blog\/wp-json\/wp\/v2\/posts\/2065\/revisions"}],"predecessor-version":[{"id":3160,"href":"https:\/\/xlwings.net\/blog\/wp-json\/wp\/v2\/posts\/2065\/revisions\/3160"}],"wp:attachment":[{"href":"https:\/\/xlwings.net\/blog\/wp-json\/wp\/v2\/media?parent=2065"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/xlwings.net\/blog\/wp-json\/wp\/v2\/categories?post=2065"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/xlwings.net\/blog\/wp-json\/wp\/v2\/tags?post=2065"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}