Win32 python and excel macros

michael.pearmain at tangozebra.com michael.pearmain at tangozebra.com
Wed Oct 18 10:13:18 EDT 2006


Hi Experts,

Looking for a very quick bit on of advice on how to make some python
code run.  I'm a newbie to both VBA and Python, so i apologise if this
is very easy but i'm about to tear my hair out after googling for the
last 3 days.

I have written a large python script which inside of it creates an
Excel table, the name of this file and how many objects can change for
each project i run.

I have then written a VBA script which takes the info from Excel and
drops it into a PowerPoint Pres.

Both of these procedures work fine, but i am coming unstuck when i try
to apply the macro, (or .xla) file to the new tables autmatically.  Can
anyone give me any guidance on this?

The macro is called sub is CTP and the add-in file is CTP.XLA

Below is the code i've managed to 'Stick' together

Mike

import win32com.client
xl = win32com.client.Dispatch("Excel.Application")
ppt = win32com.client.Dispatch("PowerPoint.Application")
xl.Visible = 1 #open MS Excel
ppt.Visible = 1 #open MS Powerpoint
xl.Workbooks.Open('Z:\\projects\\surveys\\SPSS - Generic files\\big
output.xls') #A table for a project
xl.Workbooks.Open('Z:\\projects\\surveys\\SPSS - Generic
files\\CTP.xla') # Stored macro add-in
ppt.Presentations.Open('Z:\\projects\\surveys\\SPSS - Generic
files\\Basic Template.ppt')
xl.Application.ExecuteExcel4macro('CTP!CTP.xla()"[big output.XLS]')




More information about the Python-list mailing list