Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cannot create multiple instances of PowerPoint

Tags:

c#

powerpoint

I'm working on a project where I need to use PowerPoint from C#.net. Initially, I always created one single instance. As of today, I would like to have multiple instance running. I do that like so:

Type powerpointType = Type.GetTypeFromProgID("PowerPoint.Application");

object instance1 = Activator.CreateInstance(powerpointType);
object instance2 = Activator.CreateInstance(powerpointType);

but when I ask for the handle of both instances, by calling

hwnd = (int)powerpointType.GetProperty("HWND").GetValue(instance1, null);

then I get the same handle twice. My conclusion is that the application is started just once, and the TaskManager comfirms that: Only one process.

How come there is only one instance of PowerPoint running, and how can I make it work?

like image 517
astellin Avatar asked Mar 06 '10 17:03

astellin


4 Answers

Instead of multiple instances, why not reference the multiple open presentations in the single instance?

When a user "Quits a column," you can just close that one presentation, but leave PPT open, unless it is the last open presentation.

like image 174
Jay Avatar answered Sep 30 '22 03:09

Jay


This link discusses how to use a new user account to create multiple instances of PowerPoint. It works fine if you're always running it off the same computer, but isn't particularly easy to distribute.

like image 28
Nick Avatar answered Sep 30 '22 05:09

Nick


PowerPoint as well as Word shares the same instance. Excel on the other hand lets you have multiple instances. In order to have two instances running you need to start up the other instance as a different user.

Why do you need multiple instances? In order to show two presentations on two monitors?

like image 25
Mikael Svenson Avatar answered Sep 30 '22 03:09

Mikael Svenson


Based on your comment to Mikael, there is another solution. This is VBA, but easily portable to C#. Just open the presentation (hidden) and export each slide as a PNG. Then you can have those PNGs display in your column.

Dim ap As Presentation
Set ap = Presentations.Open(FileName:="yourppt.pptx", WithWindow:=msoFalse)
Dim s As Slide
For Each s In ap.Slides
    s.Export s.Name, "PNG"
Next

Then, when someone clicks something, the first one can close and your new PPT can show.

like image 23
Todd Main Avatar answered Sep 30 '22 05:09

Todd Main