How to use Application.WindowsForPens in the xlwings API way

The Application.WindowsForPens property in the Excel object model is a legacy property primarily used to indicate whether the system is configured for pen-based input, such as with a stylus or tablet. In the context of xlwings, a powerful Python library for automating Excel, this property can be accessed to check the pen input settings of the Excel application. While its practical use in modern automation scripts is limited, it can be relevant for applications that need to adapt their interface or behavior based on the input device type.

Functionality:
This read-only property returns a Boolean value (True or False). A return value of True signifies that the Excel application is running on a system that is set up for pen input (e.g., Windows is configured to use a tablet or touch screen with pen support). A value of False indicates the system is not configured for such input. It can be used to conditionally enable or disable certain features in a macro or script that are optimized for pen interaction.

Syntax in xlwings:
In xlwings, you access this property through the app object, which represents the Excel Application. The syntax is straightforward:

app.api.WindowsForPens

Here, app is your xlwings App instance. The .api attribute provides direct access to the underlying Excel object model, allowing you to call the native WindowsForPens property. This property does not take any parameters.

Code Example:
The following xlwings code demonstrates how to check the WindowsForPens property and print the result. This example assumes you have an Excel instance running.

import xlwings as xw

# Connect to the active Excel application
app = xw.apps.active

# Access the WindowsForPens property via the .api attribute
is_pen_enabled = app.api.WindowsForPens

# Output the result
if is_pen_enabled:
    print("The system is configured for pen input.")
else:
    print("The system is not configured for pen input.")

# Alternatively, you can directly print the Boolean value
print(f"WindowsForPens value: {is_pen_enabled}")

August 3, 2026 (0)


Leave a Reply

Your email address will not be published. Required fields are marked *