469,611 Members | 2,001 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,611 developers. It's quick & easy.

Dispatch('Excel.Application') on Vista from Task Scheduler

I have a python script that runs fine from the command line or from
within IDLE, but doesn't work through the Vista Task Scheduler.

The script downloads some csv files and then uses pywin32 to combine
the csv files into a single document. When I run it through the task
scheduler, it downloads the csv files, but then doesn't seem to launch
excel. I can't figure out what is wrong or how to add enough logging
to tell.

I'm using Python 2.6 and pywin32-212.win32-py2.6 on Vista.

Code snippet below.

Any ideas? Does it have something to do with permissioning on Vista?
I'm running the task as my regular user (that has administrative
privileges).

Thanks,
Theo
---------------
from win32com.client import Dispatch
.....
excel = Dispatch('Excel.Application')
excel.visible =0
print 'launched excel'
workbook =excel.Workbooks.Add()
Sheets = workbook.sheets
defaultWorksheets = workbook.Worksheets(1)
excel.application.displayalerts = 0

for port in portList:
print 'about to open' + basePath + port.filename
port_book = excel.Workbooks.Open( basePath +
port.filename)
port_sheets = port_book.Sheets

datasheet = port_sheets(1)

datasheet.Activate()
datasheet.Cells.Select()

excel.Selection.Copy()

Sheets.Add().Name = port.name
newsheet=workbook.Worksheets(port.name)
newsheet.Activate()
newsheet.Paste()

port_book.Close(SaveChanges=0)

Nov 8 '08 #1
1 4274
Cupric wrote:
I have a python script that runs fine from the command line or from
within IDLE, but doesn't work through the Vista Task Scheduler.

The script downloads some csv files and then uses pywin32 to combine
the csv files into a single document. When I run it through the task
scheduler, it downloads the csv files, but then doesn't seem to launch
excel. I can't figure out what is wrong or how to add enough logging
to tell.

I'm using Python 2.6 and pywin32-212.win32-py2.6 on Vista.

Code snippet below.

Any ideas? Does it have something to do with permissioning on Vista?
I'm running the task as my regular user (that has administrative
privileges).

Thanks,
Theo
---------------
from win32com.client import Dispatch
....
excel = Dispatch('Excel.Application')
excel.visible =0
print 'launched excel'
workbook =excel.Workbooks.Add()
Sheets = workbook.sheets
defaultWorksheets = workbook.Worksheets(1)
excel.application.displayalerts = 0

for port in portList:
print 'about to open' + basePath + port.filename
port_book = excel.Workbooks.Open( basePath +
port.filename)
port_sheets = port_book.Sheets

datasheet = port_sheets(1)

datasheet.Activate()
datasheet.Cells.Select()

excel.Selection.Copy()

Sheets.Add().Name = port.name
newsheet=workbook.Worksheets(port.name)
newsheet.Activate()
newsheet.Paste()

port_book.Close(SaveChanges=0)
Normally this has more to do with the context that the app runs in under Task
Scheduler not having the same environment as the logged in user. Try telling
the Task Scheduler to run the application using the same credentials as the
foreground user to see if that makes a difference.

-Larry
Nov 9 '08 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

13 posts views Thread by Allison Bailey | last post: by
4 posts views Thread by federico | last post: by
3 posts views Thread by RJ | last post: by
2 posts views Thread by Ray | last post: by
2 posts views Thread by lialie | last post: by
2 posts views Thread by Silgd1 | last post: by
reply views Thread by gheharukoh7 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.