4
votes

I'm building a add-in for PowerPoint and need to access the Slides or Slide objects, or even the whole presentation; alas, the only method I can see of doing this is to open a new ppt file. Right now I'm having to resort to the hacky method of saving the current presentation and reopening it with Packaging to manipulate anything (more specifically I'm having to SHA the Slide objects from the pptx file to see if they've changed -- not ideal)

Is there any way to open the file that is currently open in PowerPoint w/o having to IO a file?

Thanks for your help, P

1

1 Answers

0
votes

I assume you have created a PowerPoint (2007/2010) Add-In Project in VisualStudio. In general you can Access the active presentation with static class Globals this way:

Globals.ThisAddIn.Application.ActivePresentation.Slides[slideIndex] ...

Edit: Example for usage:

using PowerPoint = Microsoft.Office.Interop.PowerPoint;

...

try
{
    int numberOfSlides = Globals.ThisAddIn
        .Application.ActivePresentation.Slides.Count;

    if (numberOfSlides > 0)
    {
        // get first slide
        PowerPoint.Slide firstSlide = Globals.ThisAddIn
            .Application.ActivePresentation.Slides[0];

        // get first shape (object) in the slide
        int shapeCount = firstSlide.Shapes.Count;

        if (shapeCount > 0)
        {
            PowerPoint.Shape firstShape = firstSlide.Shapes[0];
        }

        // add a label
        PowerPoint.Shape label = firstSlide.Shapes.AddLabel(
                Orientation: Microsoft.Office.Core
                   .MsoTextOrientation.msoTextOrientationHorizontal,
                Left: 100,
                Top: 100,
                Width: 200,
                Height: 100);

        // write hello world with a slidenumber
        label.TextFrame.TextRange.Text = "Hello World! Page: ";
        label.TextFrame.TextRange.InsertSlideNumber();
    }
}
catch (Exception ex)
{
    System.Windows.Forms.MessageBox.Show("Error: " + ex);

}