Automating Microsoft Powerpoint

One more example how to automate Microsoft Powerpoint and printout a
postscript file with a specified postscript printer (yes, more than one
printers can be installed on the system).

Multithreadding:

Unlike Word and Excel Powerpoint can not run in multiple instances.
If you want to use Powerpoint server based you must implement code to
handle the Powerpoint processes.

How to call the function:

You simply call the function with the name of the Word file, Postscript file and the printername which you want to use.:

e.g.:

make_ps.powerpoint(‘c:\test\powerpointfilename.ppt’, ‘c:\test\psfilename.ps’, ‘My Postscript Printername’)

The source code:

def powerpoint(powerpointfile, psfile, printer):
    pythoncom.CoInitializeEx(pythoncom.COINIT_APARTMENTTHREADED)
    myPowerpoint = win32com.client.DispatchEx('Powerpoint.Application')
    myPpt = myPowerpoint.Presentations.Open(powerpointfile, False, False, False)
    myPpt.PrintOptions.PrintInBackground = 0
    myPpt.PrintOptions.ActivePrinter = printer
    myPpt.Saved = 1
    myPpt.PrintOut(1, 5000, psfile, 0, False)
    myPpt.Close()
    #myPowerpoint.Quit()
    del myPpt
    #del myPowerpoint
    pythoncom.CoUninitialize()

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.