Author Topic: xl_app  (Read 618 times)

jelkhoury

  • Newbie
  • *
  • Posts: 14
  • Karma: +0/-0
    • View Profile
xl_app
« on: January 10, 2015, 02:20:42 PM »
I m trying to get familiar with how to use xl ranges in my python code
I started by trying the first example in Pyxll online doc :
def xl_app():
    xl_window = pyxll.get_active_object()
    xl_app = win32com.client.Dispatch(xl_window).Application
    win32com.client.gencache.EnsureDispatch(xl_app)
    return xl_app

@xl_macro()
def button_example():
    xl = xl_app()
    range = xl.Range("button_output")
    range.Value = range.Value + 1

when I attach this macro to an xl button nothing happened when I push the button
win32com is imported fine but
when I check the logfile I see this:
2015-01-10 14:05:52,130 - ERROR : Error calling function button_example
2015-01-10 14:05:52,131 - ERROR : Traceback (most recent call last):
2015-01-10 14:05:52,131 - ERROR :   File "c:\my_python_modules\my_xl_addin_module.py", line 29, in button_example
2015-01-10 14:05:52,131 - ERROR :     xl = xl_app()
2015-01-10 14:05:52,131 - ERROR :   File "c:\my_python_modules\my_xl_addin_module.py", line 18, in xl_app
2015-01-10 14:05:52,131 - ERROR :     xl_window = get_active_object()
2015-01-10 14:05:52,131 - ERROR : RuntimeError: couldn't find EXCEL7 windows

It seems that get_active_object is looking and not finding EXCEL7
I am running EXCEL2013

Can you please help
Thank you

Tony

  • Administrator
  • Hero Member
  • *****
  • Posts: 594
  • Karma: +14/-1
    • View Profile
Re: xl_app
« Reply #1 on: January 13, 2015, 03:26:18 PM »
Hi,

can I take it from your subsequent posts that this is now working for you?

Best regards,
Tony

jelkhoury

  • Newbie
  • *
  • Posts: 14
  • Karma: +0/-0
    • View Profile
Re: xl_app
« Reply #2 on: January 14, 2015, 05:43:20 AM »
yes

thank you