Sunday, December 7, 2008

Display the slide number and the total slides in PowerPoint 2007

 

Display the slide number and the total slides in PowerPoint 2007

One of my customers asked me a question about PowerPoint 2007. He wanted to have the slide number and the total number of the slides in his presentations (ie: 3/45). I quickly developped a VSTO 3.0 Addin and here is the code. I created a Ribbon Button to call this method. I simply put this method in the ThisAddin.cs file:

/// <summary>

/// Format the slide numbers with: number/total number

/// </summary>

public void FormatSlideNumbers()

{

int iSlides = 0;

string SlideCounterName = "Slide Number Placeholder";

try

{

// For every Slide in the Active Presentation

for ( iSlides = 1; iSlides <= this.Application.ActivePresentation.Slides.Count; iSlides++)

{

// For every Shape in the Slide

foreach (PowerPoint.Shape myShape in Application.ActivePresentation.Slides[iSlides].Shapes)

{

// Check the shape containing "Slide Number Placeholder"

if (myShape.Name.Contains(SlideCounterName))

{

string CurrentslideNumber = iSlides.ToString();

// Change the Slide's placeholder's name

myShape.TextFrame.TextRange.Text = CurrentslideNumber + @"/" + this.Application.ActivePresentation.Slides.Count.ToString();

myShape.Width = PowerPointAddInTools.Properties.Settings.Default.SlideWidth;

}

}

}

}

catch (Exception ex)

{

System.Windows.Forms.MessageBox.Show("An error has occured: " + ex.Message, "PowerPoint Tools", System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Error);

}

Enjoy !

Published Sunday, December 07, 2008 9:32 PM by joyantas

Information Worker Experiences : Display the slide number and the total slides in PowerPoint 2007

No comments:

Blog Archive