Jd H wrote:
> Hello,
>  
> I have the below python code which opens an excel sheet, runs a macro
> then save the file. When run from python it runs perfectly. Code is
> below. File name is test.py
>  
> <<< 
> from win32com.client import Dispatch
>  
> myExcel = Dispatch('Excel.Application')
> myExcel.Visible = 1
> myExcel.Workbooks.Add('C:\Python24\test.xls')

I don't believe this ever ran correctly as you have posted it.  This
will not open a file called "test.xls" in the directory "Python24". 
Instead, this will open a file in the root called "Python24<tab>est.xls"
with a tab character in the name.  You HAVE to be careful about
backslashes in Python.  Either double the backslashes, replace them with
forward slashes, or use a raw string ( r'c:\Python24\test.xls' ).

> myExcel.Workbooks.Add('C:\Python24\macro.XLA')
> myExcel.Run('Macro1')
> myExcel.Application.DisplayAlerts = False
> myExcel.ActiveWorkbook.SaveAs('C:\Python24\test.xls')
> myExcel.Quit()
> >>> 
>  
> When run from cron, it fails at line 3 when it opens the file with
> below message:
>  
> Traceback (most recent call last):
>   File "c:\Python24\test.py", line 20, in ?
>     jd.Workbooks.Add('C:\Python24\test.xls')
>   File "C:\Python24\Lib\site-packages\win32com\client\dynamic.py",
> line 496, in __getattr__
>     raise AttributeError, "%s.%s" % (self._username_, attr)
> AttributeError: Excel.Application.Workbooks
>  
> Any ideas how to resolve this?

What utility are you using to schedule this?  Are you actually using
Cygwin's cron, or the "at" command, or the standard "Schedule Tasks"
thing, or what?  What operating system are you using?

Most of the task scheduler tools run as a service.  By default, a
service cannot launch a GUI application.  Also, in some cases, the
services run as a user that has restricted rights.   Tell us a little
more about how you are doing this, and perhaps we can suggest how to
accomplish it.

-- 
Tim Roberts, [EMAIL PROTECTED]
Providenza & Boekelheide, Inc.

_______________________________________________
python-win32 mailing list
python-win32@python.org
http://mail.python.org/mailman/listinfo/python-win32

Reply via email to