{"id":2135,"date":"2026-06-20T07:05:23","date_gmt":"2026-06-19T23:05:23","guid":{"rendered":"https:\/\/xlwings.net\/blog\/?p=2135"},"modified":"2026-03-28T07:55:19","modified_gmt":"2026-03-28T07:55:19","slug":"how-to-use-applicationlibrarypath-in-the-xlwings-api-way","status":"publish","type":"post","link":"https:\/\/xlwings.net\/blog\/how-to-use-applicationlibrarypath-in-the-xlwings-api-way\/","title":{"rendered":"How to use Application.LibraryPath in the xlwings API way"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">The <strong>LibraryPath<\/strong> property of the <strong>Application<\/strong> object in Excel is a read-only string that returns the complete path to the folder where the Microsoft Excel library (or add-ins) is installed on the user&#8217;s system. This path is typically where Excel stores its built-in add-in files (with .xlam, .xll extensions, etc.) and is part of the application&#8217;s installation directory structure. In xlwings, this property can be accessed via the <code>api<\/code> property, which provides direct access to the underlying Excel object model. It is useful for developers who need to programmatically locate Excel&#8217;s library directory, for instance, when loading specific add-ins, referencing template files stored with Excel, or ensuring file paths are correctly resolved in cross-platform scenarios.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Syntax in xlwings:<\/strong><br>The property is accessed through the <code>Application<\/code> object. In xlwings, you typically start by instantiating an <code>App<\/code> or using the active app. The syntax is:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>app.api.LibraryPath<\/code><\/pre>\n\n\n\n<ul class=\"wp-block-list\">\n<li><code>app<\/code>: This is an xlwings <code>App<\/code> object representing the Excel application instance.<\/li>\n\n\n\n<li><code>api<\/code>: This property exposes the native Excel object model (via COM or AppleScript).<\/li>\n\n\n\n<li><code>LibraryPath<\/code>: The property name, which requires no parameters.<\/li>\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\">The return value is a string containing the full directory path (e.g., <code>C:\\Program Files\\Microsoft Office\\root\\Office16\\LIBRARY<\/code> on Windows). Note that the exact path may vary based on the Office version, installation type, or operating system.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Example Usage:<\/strong><br>Here are practical xlwings API code examples demonstrating how to retrieve and use the LibraryPath property:<\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li><strong>Basic Retrieval:<\/strong><br>This example gets the library path from the active Excel application and prints it.<\/li>\n<\/ol>\n\n\n\n<pre class=\"wp-block-code\"><code>import xlwings as xw\n# Connect to the active Excel instance\napp = xw.apps.active\n# Access the LibraryPath property\nlib_path = app.api.LibraryPath\nprint(f\"Excel Library Path: {lib_path}\")<\/code><\/pre>\n\n\n\n<ol start=\"2\" class=\"wp-block-list\">\n<li><strong>Using with New Instance:<\/strong><br>If you launch a new Excel application via xlwings, you can obtain its library path similarly.<\/li>\n<\/ol>\n\n\n\n<pre class=\"wp-block-code\"><code>import xlwings as xw\n# Start a new Excel application\napp = xw.App(visible=True)\n# Get the library path\nlib_path = app.api.LibraryPath\nprint(f\"Library folder: {lib_path}\")\n# Optionally, you can list files in the library directory\nimport os\nif os.path.exists(lib_path):\n    files = os.listdir(lib_path)\n    print(f\"Files in library: {files&#91;:5]}\") # Show first 5 files\napp.quit()<\/code><\/pre>\n\n\n\n<ol start=\"3\" class=\"wp-block-list\">\n<li><strong>Practical Application \u2013 Loading an Add-in:<\/strong><br>You can use the LibraryPath to construct full paths to add-ins. This example checks for a specific add-in and loads it if available.<\/li>\n<\/ol>\n\n\n\n<pre class=\"wp-block-code\"><code>import xlwings as xw\nimport os\napp = xw.apps.active\nlib_path = app.api.LibraryPath\n# Define a target add-in name (e.g., Analysis ToolPak)\naddin_name = \"ANALYS32.XLL\"\naddin_path = os.path.join(lib_path, addin_name)\n# Check if the add-in exists and load it\nif os.path.exists(addin_path):\n    app.api.AddIns(addin_name).Installed = True\n    print(f\"Loaded add-in from: {addin_path}\")\nelse:\n    print(f\"Add-in not found at {addin_path}\")<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\"><\/p>\n","protected":false},"excerpt":{"rendered":"<p>The **LibraryPath** property of the **Application** object in Excel is a read-only string 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-2135","post","type-post","status-publish","format-standard","hentry","category-xlwings-api-reference"],"_links":{"self":[{"href":"https:\/\/xlwings.net\/blog\/wp-json\/wp\/v2\/posts\/2135","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=2135"}],"version-history":[{"count":2,"href":"https:\/\/xlwings.net\/blog\/wp-json\/wp\/v2\/posts\/2135\/revisions"}],"predecessor-version":[{"id":3263,"href":"https:\/\/xlwings.net\/blog\/wp-json\/wp\/v2\/posts\/2135\/revisions\/3263"}],"wp:attachment":[{"href":"https:\/\/xlwings.net\/blog\/wp-json\/wp\/v2\/media?parent=2135"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/xlwings.net\/blog\/wp-json\/wp\/v2\/categories?post=2135"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/xlwings.net\/blog\/wp-json\/wp\/v2\/tags?post=2135"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}