1

I am new to python, trying to automate powerpoint using win32com. I am unable to import or use constants in my scripts. I have ran makepy to create libraries. below is the error messages & script. Can someone tell me how to import constants ?

Script :

import win32com.client

Application    =win32com.client.gencache.EnsureDispatch("PowerPoint.Application")
Presentation = Application.Presentations.Add()
Base = Presentation.Slides.Add(1, ppLayoutBlank)

Error messages :

Traceback (most recent call last): File "ppt.py", line 14, in Base = Presentation.Slides.Add(1, ppLayoutBlank) NameError: name 'ppLayoutBlank' is not defined

Vasanth
  • 11
  • 2

2 Answers2

0

The INTEROP method you have chosen depends on the application interface to which you are connecting.

Not defined usually means that there is no such variable, but Python more often raises NameError in such cases. So what is exactly happening here is a little unclear.

So, depends on the version of PPoint on how to communicate with it.

I advise you to use pywinauto instead and go for "brute_force", i.e. emulate key presses and/or clicks etc. on right buttons, menues etc.

Because the names of thous is little less likely to change trough out the versions than a COM interface.

Microsoft has a nasty habit of changing just a little bit the interface, and then a program stops working.

If you want to insist on win32com, you will have to read PPoint's documentation for a specific version (or Office version), and for win32com for your Python version.

You should see whether you should start a COM Client or is there some other MS tweak you need to employ.

Dalen
  • 4,128
  • 1
  • 17
  • 35
0

I'm under Linux now and cannot test here, but try to

import win32com.client.constants

... and then look for the constants defined in that module. See also How to use win32com.client.constants with MS Word?.

Community
  • 1
  • 1
Dr. V
  • 1,747
  • 1
  • 11
  • 14