Search code examples
pythonpowerpointpython-pptx

Open Powerpoint and select a specific slide-number using Python?


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...)


Solution

  • 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')