Sunday, 15 September 2013

how to execute F9 for excel spreadseet in python

how to execute F9 for excel spreadseet in python

I'm using python to execute some external command on excel.
x1 = win32com.client.DispatchEx("Excel.Application")
wb = x1.workbooks.open(filePath+fileName);
x1.run("fileName!someMacro")
results+=[(wb.ActiveSheet.Cells(4,8).Value,
wb.ActiveSheet.Cells(4,16).Value)];
And it is working, runs the macro and I can collect the results. I have
another sheet - there in Formulas bar I have a button "Calculate Now" / F9
I would like to run F9 and collect results from that sheet. But the
following code doesn't seems to executes F9 - thus I'm getting all the
results with same values.
results = []
sheet2=wb.Sheets(5).Select
for i in range(n):
wb.Sheets(5).Calculate
results+=[(wb.Sheets(5).Cells(12,11).Value,
wb.Sheets(5).Cells(12,10).Value];
How can I execute the F9 for excel from python?

No comments:

Post a Comment