1

Open an existing PowerPoint Presentation from a directory Example from here: Charts from Excel to PowerPoint with Python

My situation is different - the link showed how to to open a new presentation not a saved existing one.

error message:

module None.

Johnseito
  • 315
  • 1
  • 9
  • 24

1 Answers1

1

You can call out to the open cmd and pass the filename to be opened as the only parameter. It will query the registry to find the program that should be used as default to open such a file, how to do it, and then do it.

This should work, did not check though

subprocess.run(['open', 'the file to be opened.pptx'])

Update: There is also https://docs.python.org/3/library/os.html#os.startfile

user2722968
  • 13,636
  • 2
  • 46
  • 67
  • I am opening it to add excel charts and graphs and text and tables to it. I don't know if the language you are using will help with doing that. – Johnseito Jul 09 '17 at 15:07
  • I was under the impression that by "opening" you mean "present to the user". [Here](http://www.s-anand.net/blog/automating-powerpoint-with-python/) is an example of how to use win32com to open an existing pptx and modify it. – user2722968 Jul 09 '17 at 15:10
  • Ok - but how do you open it from a saved directory. I saw that link before and I was trying to figure out this argument Presentation = Application.Presentations.Open(sys.argv[1]) and how to put the path and filename there ? – Johnseito Jul 09 '17 at 15:14
  • `sys.argv[1]` refers to the first argument given to the script while executing; that is `python foobar.py openme.pptx` would open `openme.pptx`. Replace the parameter to `Open()` with a string or a variable holding your filename – user2722968 Jul 09 '17 at 15:16
  • actually I did that and couldn't open it. I think maybe I need to install python-pptx ? The error I got is pywintypes.com_error: (-2147352567, 'Exception occurred.', (0, None, None, None, 0, -2147024773), None) – Johnseito Jul 09 '17 at 15:34
  • Do you think I need to install python-pptx package ? – Johnseito Jul 09 '17 at 16:05
  • I can't tell, the error is most unhelpful. `win32com` should work, though. You may want to google for 'win32com powerpoint' and see if there are more knobs to be turned. `python-pptx` seem capable as well. – user2722968 Jul 09 '17 at 16:09
  • I could open excel no problem but that error always comes up when I try to open powerpoint. – Johnseito Jul 09 '17 at 21:35