Judging by other posts such as Python Window Activation this might not be as simple as I was hoping, but I'm compelled to ask anyway.
In the snippet below, using win32com.client
and Application.Presentations.Open(ppt1, ReadOnly=0)
will open and activate a powerpoint presentation. Using Application.Presentations.Open(ppt2, ReadOnly=0)
will open and activate another powerpoint presentation. As you will see, I can easily reference the former presentation and do SOME things with it, but it will NOT become the active window. How can this be accomplished?
Here's what I've been working with:
# The following requires two existing presentations
# ppt1.pptx and ppt2.pptx in a directory named C:\\pptTest\\
import win32com.client
Application = win32com.client.Dispatch("PowerPoint.Application")
directory = 'C:\\pptTest\\'
ppt_a = 'ppt_a.pptx'
ppt_b = 'ppt_b.pptx'
presentation_a = directory + ppt_a
presentation_b = directory + ppt_b
pres_a = Application.Presentations.Open(presentation_a, ReadOnly=0)
pres_b = Application.Presentations.Open(presentation_b, ReadOnly=0)
pres_a_slide1 = pres_a.Slides.Add(len(pres_a.Slides)+1, 12)
shape_a_1 = pres_a_slide1.Shapes.AddTextbox(Orientation=0x1,Left=100,Top=50,Width=400,Height=100)
shape_a_1.TextFrame.TextRange.Text='PRESENTATION A'
##%%
pres_b_slide1 = pres_b.Slides.Add(len(pres_b.Slides)+1, 12)
shape1 = pres_b_slide1.Shapes.AddTextbox(Orientation=0x1,Left=100,Top=50,Width=400,Height=100)
shape1.TextFrame.TextRange.Text='PRESENTATION B'
Result:
As you can see by the example, I can still reference the first presentation after opening another, but I can't make it the active window. The reason why I'm so interested in this, is that some methods will not work properly unless the presentation I'm editing through Python is also the active window. I'll get into those details as well if that is interesting to anyone.
Thank you for any suggestions!