How to use Application.Excel4IntlMacroSheets in the xlwings API way

The Excel4IntlMacroSheets property of the Application object in Excel’s object model is a legacy feature primarily used for backward compatibility with older Excel 4.0 international macro sheets. In xlwings, this property can be accessed to retrieve a collection of sheets that are specifically Excel 4.0 international macro sheets within a workbook. These sheets are a type of macro sheet that was used in earlier versions of Excel for storing macro commands and functions, particularly in international contexts where different language settings were involved. While modern Excel development typically uses VBA (Visual Basic for Applications) for macros, the Excel4IntlMacroSheets property remains available for compatibility reasons, allowing developers to interact with or reference these legacy components programmatically.

In xlwings, the Excel4IntlMacroSheets property is accessed through the app object, which represents the Excel application. The syntax for using this property in xlwings is straightforward, as it returns a collection of sheet objects that correspond to the Excel 4.0 international macro sheets. The property does not take any parameters, making it simple to call. Here is the basic syntax:

import xlwings as xw

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

# Access the Excel4IntlMacroSheets property
intl_macro_sheets = app.api.Excel4IntlMacroSheets

In this code, app.api.Excel4IntlMacroSheets calls the underlying Excel object model property via xlwings’ api attribute, which provides direct access to Excel’s COM interface. The returned value is a collection that can be iterated over to access individual sheets. Each sheet in this collection is an object representing an Excel 4.0 international macro sheet, and you can use properties like Name to get the sheet’s name or Visible to check its visibility. Note that this property may return None or an empty collection if no such sheets exist in the workbook, so it’s good practice to handle such cases in your code.

For example, to list all Excel 4.0 international macro sheets in the active workbook, you can use the following xlwings code:

import xlwings as xw

# Start or connect to Excel
app = xw.apps.active

# Get the Excel4IntlMacroSheets collection
intl_macro_sheets = app.api.Excel4IntlMacroSheets

# Check if there are any sheets in the collection
if intl_macro_sheets is not None and intl_macro_sheets.Count > 0:
    for sheet in intl_macro_sheets:
        print(f"Sheet Name: {sheet.Name}, Visible: {sheet.Visible}")
else:
    print("No Excel 4.0 international macro sheets found.")

This code iterates through each sheet in the Excel4IntlMacroSheets collection and prints its name and visibility status. It includes error handling to account for cases where no such sheets are present. Additionally, you can perform operations on these sheets, such as activating them or reading data, though this is less common in modern workflows due to the deprecated nature of Excel 4.0 macros. For instance, to activate the first Excel 4.0 international macro sheet, you could use:

if intl_macro_sheets is not None and intl_macro_sheets.Count > 0:
    first_sheet = intl_macro_sheets(1) # Indexing starts at 1 in Excel
    first_sheet.Activate()
    print(f"Activated sheet: {first_sheet.Name}")

June 5, 2026 (0)


Leave a Reply

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