{"id":2243,"date":"2026-08-13T07:11:52","date_gmt":"2026-08-12T23:11:52","guid":{"rendered":"https:\/\/xlwings.net\/blog\/?p=2243"},"modified":"2026-03-28T11:48:39","modified_gmt":"2026-03-28T11:48:39","slug":"how-to-use-workbookcancheckout-in-the-xlwings-api-way","status":"publish","type":"post","link":"https:\/\/xlwings.net\/blog\/how-to-use-workbookcancheckout-in-the-xlwings-api-way\/","title":{"rendered":"How to use Workbook.CanCheckOut in the xlwings API way"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">The <code>CanCheckOut<\/code> member of the <code>Workbook<\/code> object in Excel&#8217;s object model is a read-only property that indicates whether a workbook stored on a Microsoft SharePoint server can be checked out to the local machine. This property is particularly useful in collaborative environments where multiple users may need to edit a shared workbook. By checking this property, a developer can determine if the workbook is available for exclusive editing before attempting a check-out operation, thus preventing potential errors or conflicts.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">In xlwings, you can access the <code>CanCheckOut<\/code> property through the <code>api<\/code> property of a <code>Book<\/code> object, which provides direct access to the underlying Excel object model. The syntax for using this property is straightforward. Given an xlwings <code>Book<\/code> object, you can call the property as follows:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>can_checkout_status = workbook.api.CanCheckOut<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Here, <code>workbook<\/code> is an xlwings <code>Book<\/code> instance representing the open workbook. The <code>api<\/code> property exposes the native Excel VBA object model, allowing you to use the <code>CanCheckOut<\/code> property directly. The property returns a Boolean value: <code>True<\/code> if the workbook can be checked out from the server, and <code>False<\/code> otherwise. This check is essential before proceeding with the <code>CheckOut<\/code> method, which would otherwise throw an error if the workbook cannot be checked out.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">For example, consider a scenario where you have a workbook opened from a SharePoint location. You can use the following code to verify its check-out status:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>import xlwings as xw\n\n# Open the workbook from a SharePoint path or a local path linked to SharePoint\nwb_path = r'https:\/\/your-sharepoint-site.com\/path\/to\/workbook.xlsx'\nwb = xw.Book(wb_path)\n\n# Check if the workbook can be checked out\nif wb.api.CanCheckOut:\n    print(\"The workbook can be checked out. Proceeding with check-out...\")\n    wb.api.CheckOut(wb_path) # Check out the workbook to the local machine\nelse:\n    print(\"The workbook cannot be checked out at this time. It may already be checked out by another user or not stored on a server.\")<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">In this example, the code first opens the workbook using xlwings. It then uses <code>wb.api.CanCheckOut<\/code> to determine if a check-out is possible. If it returns <code>True<\/code>, the code proceeds to call the <code>CheckOut<\/code> method, passing the workbook path as an argument to perform the check-out. If it returns <code>False<\/code>, a message is printed, indicating the workbook is unavailable for check-out, which helps avoid runtime errors.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Another practical use case is in automated scripts that manage document workflows. For instance, before performing any edits, you might want to ensure the workbook is checked out to prevent overwriting conflicts:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>import xlwings as xw\n\n# Assume the workbook is already open or referenced\nwb = xw.books.active # Get the active workbook\n\n# Verify check-out capability\nif wb.api.CanCheckOut:\n    try:\n        wb.api.CheckOut(wb.fullname) # Attempt to check out using the workbook's full path\n        print(f\"Workbook '{wb.name}' has been successfully checked out.\")\n        # Perform edits here\n        # wb.sheets&#91;0].range('A1').value = 'Updated Data'\n    except Exception as e:\n        print(f\"An error occurred during check-out: {e}\")\nelse:\n    print(f\"Workbook '{wb.name}' is not available for check-out. Please check server status or user permissions.\")<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\"><\/p>\n","protected":false},"excerpt":{"rendered":"<p>The `CanCheckOut` member of the `Workbook` object in Excel&apos;s object model is a read-only property th&#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-2243","post","type-post","status-publish","format-standard","hentry","category-xlwings-api-reference"],"_links":{"self":[{"href":"https:\/\/xlwings.net\/blog\/wp-json\/wp\/v2\/posts\/2243","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=2243"}],"version-history":[{"count":2,"href":"https:\/\/xlwings.net\/blog\/wp-json\/wp\/v2\/posts\/2243\/revisions"}],"predecessor-version":[{"id":3427,"href":"https:\/\/xlwings.net\/blog\/wp-json\/wp\/v2\/posts\/2243\/revisions\/3427"}],"wp:attachment":[{"href":"https:\/\/xlwings.net\/blog\/wp-json\/wp\/v2\/media?parent=2243"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/xlwings.net\/blog\/wp-json\/wp\/v2\/categories?post=2243"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/xlwings.net\/blog\/wp-json\/wp\/v2\/tags?post=2243"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}