Using win32com to combine powerpoint presentations by copying slides

Viewed 581

I'm trying to write a python script that combines slides from different powerpoint presentations into a new standalone presentation. The following code copies a single slide (in this case slide 11) from an existing presentation and pastes it into a new presentation at the insert_index:

import win32com.client

source_path = "source_path"
target_path = "target_path"

ppt_instance = win32com.client.Dispatch('PowerPoint.Application')
read_only = True
has_title = False
window = False
source_prs = ppt_instance.Presentations.open(source_path, read_only, has_title, window)
target_prs = ppt_instance.Presentations.Add()
nr_slide = 11
insert_index = 1
source_prs.Slides(nr_slide).Copy()
target_prs.Slides.Paste(Index=insert_index)
 
target_prs.SaveAs(target_path)
target_prs.Close()
source_prs.Close()
 
ppt_instance.Quit()
del ppt_instance

However, this unfortunately changes the colors of some objekts. How can I get around this?

I appreciate your help.

0 Answers
Related