AppleScript to copy PowerPoint slide from one presentation to another

53 views Asked by At

I've got a PowerPoint file with a single slide and my goal is to copy that one slide into a different PowerPoint file.

Using macOS Sonoma 14.0 with Microsoft Office 365 PowerPoint 16.78 (late 2023)

I've tried several variations of:

tell application "Microsoft PowerPoint"
    activate

    -- Get the source and destination presentations
    set sourcePresentation to open presentation file "source.pptx"
    set destinationPresentation to open presentation file "destination.pptx"

    -- Get the slide to copy from the source presentation
    set sourceSlide to slide 1 of sourcePresentation

    -- Copy the slide to the destination presentation
    copy object sourceSlide
    paste object to destinationPresentation

    -- Close the source presentation
    close presentation sourcePresentation
end tell

Ultimately I'd like to point the final script at a folder full of .pptx files and have it insert the slide into each of destination deck in the second position. But I'd settle for a basic slide copy across decks right now. :)

1

There are 1 answers

0
Mockman On

This should get you started. Note that there is a switch in 'mode' from presentation to window in order to use the paste object command.

It seems that the paste object will deposit whatever had been copied to after the selection — in this case, after slide 1.

tell application "Microsoft PowerPoint"
    activate
    
    -- source   
    copy object slide 1 of presentation "source.pptx"
    
    -- destination
    select slide 1 of presentation "destination.pptx"
    
    tell active window
        set view type to slide sorter view
        paste object its view
        -- paste object view of active window -- alternate phrasing for when outside of tell block
        set view type to normal view
    end tell
    select slide 2 of presentation "destination.pptx" -- optional
    
end tell

You should be able to find numerous answers here that demonstrate using a repeat loop to cycle through a list of files.

Specific to powerpoint though, the syntax for opening a file is just open followed by the file reference. You can get the file reference by using the choose file command. Try running something like choose file in a separate script and it will return the appropriate file reference. Then use that result with your open command in this script.