PPT.WorkWithSections in MS PowerPoint 2010 to Insert, Move, Get Section Counts in VB.NET
In this article I am going to explain about how to Insert, Move, Get Section Counts in a Microsoft PowerPoint 2010 presentation.
Introduction
In this article I am going to explain about how to Insert, Move, Get Section Counts in a Microsoft PowerPoint 2010 presentation. For this we use PPT.WorkWithSections in Microsoft PowerPoint 2010. Using PPT.WorkWithSections we can insert sections, get counts and names of sections, and move sections in a Microsoft PowerPoint 2010 presentation.
Microsoft Office 2010 offer some powerful tools, using this tools you can create application. Using Microsoft Visual Basic for Applications (VBA) you can create your own application according to your need. These application can performer some specific task.
For creating application we can use
- VBA host of Excel 2010
- VBA host of PowerPoint 2010
- VBA host of Word 2010
NOTE : OneNote 2010 is not a VBA host.
Code that we use in this application are given below
Sub DemoSections()
SetupDemo()
Dim a As Integer
With ActivePresentation.SectionProperties
.AddBeforeSlide(2, "Test Section 1")
.AddBeforeSlide(5, "Test Section 2")
.AddBeforeSlide(9, "Test Section 3")
.AddSection(1, "Intro Section")
For a = 1 To .Count
Debug.Print "Section " & a & "(" & .Name(a) & ") contains " & _
.SlidesCount(a) & " slide(s);";
Debug.Print(" The first slide is : " & .FirstSlide(a))
.Rename(a, "New Name " & a)
Next a
.Move(2, .Count)
End With
With ActivePresentation
Dim sld As Slide
For Each sld In ActivePresentation.Slides
Debug.Print("Slide " & sld.SlideIndex & " is in section " & sld.sectionIndex)
Next sld
sld = .Slides(.Slides.Count)
sld.MoveToSectionStart(1)
ActiveWindow.ViewType = ppViewSlideSorter
For a = 1 To .SectionProperties.Count
If a Mod 2 = 0 Then
ActiveWindow.ExpandSection(a, False)
End If
Next a
Dim isExpanded As Boolean
For a = 1 To .SectionProperties.Count
isExpanded = ActiveWindow.IsSectionExpanded(a)
ActiveWindow.ExpandSection(a, Not isExpanded)
Next a
End With
With ActivePresentation.SectionProperties
For a = .Count To 1 Step -1
.Delete(a, False)
Next a
CleanupDemo()
End With
End Sub
Private Sub SetupDemo()
Dim a As Integer
With ActivePresentation
.Slides(1).Shapes(1).TextFrame.TextRange.Text = "Title"
Dim sld As Slide
For a = 1 To 10
sld = .Slides.Add(a + 1, ppLayoutText)
sld.Shapes(1).TextFrame.TextRange.Text = "Slide " & a
Next a
End With
End Sub
Private Sub CleanupDemo()
ActiveWindow.ViewType = ppViewNormal
Dim a As Integer For a = ActivePresentation.Slides.Count To 2 Step -1
ActivePresentation.Slides(a).Delete()
Next a
End Sub
Steps for creating Application
Step 1 : Start Microsoft PowerPoint 2010 :
Step 2 : Using Alt + F11 Key Start Visual Basic for Applications (VBA) Window :
Step 3 : Select on VBAProject(Presentation 1) :
Step 4 : Right Click On VBAProject(Presentation 1) ==> Goto Insert==> Goto Module & click on Module:
Step 5 : Write Code in Visual Basic for Applications (VBA) Window :
Step 6 : Run Application using F5 :
Step 7 : Macros window will open, Select Macros name and click on Run Button :
Step 8: Output of Application :
Slide Before Run application
Slide After run application