-3

is there any way to open a Powerpoint with python and goto a specific slide-number.

For example i input 5 with an input()-statement and then powerpoint open a specific ppt-file and go to the slide 5?

(i am general looking for a solution for windows - but would be also happy when it is running on macos - but this is not a must...)

Rapid1898
  • 895
  • 1
  • 10
  • 32
  • This is not a code-writing or tutoring service. We can help solve specific, technical problems, not open-ended requests for code or advice. Please edit your question to show what you have tried so far, and what specific problem you need help with. See the [How To Ask a Good Question](https://stackoverflow.com/help/how-to-ask "How To Ask a Good Question") page for details on how to best help us help you. – itprorh66 Feb 16 '22 at 20:10
  • Thanks for your reply - i think i found a solution using os.startfile and pyautogui Maybe my answer is better then my question and you give me instead an upvote for my answer... ;=) – Rapid1898 Feb 16 '22 at 21:13
  • I was going to wave you off trying to use python-pptx for this. It manipulates the underlying file, rather than the PowerPoint app itself. And thanks for mentioning pyautogui - which I wasn't familiar with. Will have to see if it works on Mac or Linux. – Martin Packer Feb 17 '22 at 08:09

1 Answers1

1

I think with this code this works as expected: (with this example the pptx-file is opened and the x-slide selected)

import os
import sys
import pyautogui
import time    

slidenum = input()
fn = r"C:\Users\xyz\input.pptx"
os.startfile(fn)
time.sleep (2)  
pyautogui.press('F5')
pyautogui.press(str(slideNum))
pyautogui.press('enter')
Rapid1898
  • 895
  • 1
  • 10
  • 32