Skip to content

get_excel_hwnds throws an error in case no Excel application is running #269

Description

@sdementen

While running nosetests, I get errors if no Excel is open when starting the tests.

Some debugging led me to an issue in the get_excel_hwnds function. The function win32gui.FindWindowEx is used in a if construct but in fact the function throws a pywintypes.error when it fails. I think the function should instead be

def get_excel_hwnds():
    hwnds = []
    win32gui.EnumWindows(lambda hwnd, result_list: result_list.append(hwnd), hwnds)

    excel_hwnds = []
    for hwnd in hwnds:
        try:
            win32gui.FindWindowEx(hwnd, 0, 'XLDESK', None)
        except pywintypes.error:
            pass
        else:
            excel_hwnds.append(hwnd)

    return excel_hwnds

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions