Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Attribute error when another excel instance has a process running #468

Closed
dhbachh opened this issue May 19, 2016 · 1 comment
Closed

Attribute error when another excel instance has a process running #468

dhbachh opened this issue May 19, 2016 · 1 comment
Labels
Milestone

Comments

@dhbachh
Copy link

dhbachh commented May 19, 2016

Hi guys,

Take the scenario whereby I have two spreadsheets open, one on which I run my xlwings function (call it fileA)and the other on which I'm currently doing something else (call it fileB)

when I have something running on fileB be it a formula highlighted or a form window open, then I run my xlwings fct on file A, that usually generates an Attribute error :
AttributeError: .Application

As a potential fix, I realised that
changing the exception handling in get_xl_apps() in file _xlwindows.py
from :

def get_xl_apps():
    xl_apps = []
    hwnds = get_excel_hwnds()
    for hwnd in hwnds:
        try:
            xl_app = get_xl_app_from_hwnd(hwnd)
            xl_apps.append(xl_app)
        except WindowsError:
            # This happens if the bare Excel Application is open without Workbook
            # i.e. there is no 'EXCEL7' child hwnd that would be necessary to make a connection
            pass
    return xl_apps

to

def get_xl_apps():
    xl_apps = []
    hwnds = get_excel_hwnds()
    for hwnd in hwnds:
        try:
            xl_app = get_xl_app_from_hwnd(hwnd)
            xl_apps.append(xl_app)
        except  (WindowsError,AttributeError):
            # This happens if the bare Excel Application is open without Workbook
            # i.e. there is no 'EXCEL7' child hwnd that would be necessary to make a connection
            pass
    return xl_apps

tends to solve the problem

@fzumstein fzumstein added the bug label May 19, 2016
@dhbachh
Copy link
Author

dhbachh commented May 19, 2016

It should be noted that sometimes, you can also get a com error as is shown on this link

http://stackoverflow.com/questions/3718037/error-while-working-with-excel-using-python

so maybe the error handling should just capture everything:

therefore try to use
except:

instead of except (WindowsError,AttributeError):

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants