Roger Heckly
Roger Heckly

Reputation: 61

Loop Through Sections in PowerPoint with C#

I try to Loop through the sections in Powerpoint using C#.

first I want to check the property ActivePresentation.HasSection, but get an error. Then the ActivePresentation.SectionCount also shows an error - also the ActivePresentation.SectionProperties.Count

my code:

if(oPresentation.HasSections == true)
{
                for (int iSection = oPresentation.SectionCount; iSection >0; iSection--)
                {
                    oPresentation.SectionProperties.Delete(iSection, false);
                }
            }

I can create section using C# with

oPresentation.SectionProperties.AddBeforeSlide(1, false)

I can delete a section using c# with

oPresentation.SectionProperties.Delete(2, false)

But does anybody knows how to Loop through the sections in PowerPoint by C# and Delete them all? How to check if a presentation has sections?

In VBA this is not a Problem: https://code.msdn.microsoft.com/office/PowerPoint-2010-Insert-b6f1e012

Upvotes: 3

Views: 717

Answers (1)

Roger Heckly
Roger Heckly

Reputation: 61

For all who are looking the same, I got it working myself. I think there is no direct Access to the oPresentation.SectionProperties.Count - after using the variable it worked. Maybe someone could explain me that, I'm new in this C#.

        PowerPoint.SectionProperties oSections = oPresentation.SectionProperties;

            if(oSections.Count > 0)
            {
                for (int iSection = oSections.Count; iSection > 0; iSection--)
                {
                    oSections.Delete(iSection, false);
                }
            }

Upvotes: 1

Related Questions