Class Slides (PowerPoint VBA)
A collection of all the Slide objects in the specified presentation. To use a Slides class variable it first needs to be instantiated, for example
Dim slds as Slides
Set slds = ActivePresentation.Slides
AddSlide
Creates a new slide, adds it to the Slides collection, and returns the slide.
If your Visual Studio solution includes the Microsoft.Office.Interop.PowerPoint reference, this method maps to the following types:
AddSlide (Index, pCustomLayout)
Dim lngIndex As Long: lngIndex =
Dim sldAddSlide As Slide
Set sldAddSlide = ActivePresentation.Slides.AddSlide(Index:=lngIndex, pCustomLayout:=)
Arguments
The following arguments are required:
Index (Long) - The index of the slide to be added.
pCustomLayout (CustomLayout) - The layout of the slide.
Count
Returns the number of objects in the specified collection.
Dim lngCount As Long
lngCount = ActivePresentation.Slides.Count
FindBySlideID
Returns a Slide object that represents the slide with the specified slide ID number. Each slide is automatically assigned a unique slide ID number when it is created. Use the SlideID property to return a slide's ID number.
Unlike the SlideIndex property, the SlideID property of a Slide object won't change when you add slides to the presentation or rearrange the slides in the presentation. Therefore, using the FindBySlideID method with the slide ID number can be a more reliable way to return a specific Slide object from a Slides collection than using the Item method with the slide's index number.
FindBySlideID (SlideID)
SlideID: Specifies the ID number of the slide you want to return. Microsoft PowerPoint assigns this number when the slide is created.
Dim lngSlideID As Long: lngSlideID =
Dim sldFindBySlideID As Slide
Set sldFindBySlideID = ActivePresentation.Slides.FindBySlideID(SlideID:=lngSlideID)
InsertFromFile
Inserts slides from a file into a presentation, at the specified location. Returns an Integer that represents the number of slides inserted.
InsertFromFile (FileName, Index, SlideStart, SlideEnd)
Dim strFileName As String: strFileName = "c:\ppt\sales.ppt"
Dim lngIndex As Long: lngIndex = 2
Dim lngInsertFromFile As Long
lngInsertFromFile = ActivePresentation.Slides.InsertFromFile(FileName:=strFileName, Index:=lngIndex)
Arguments
The following arguments are required:
FileName (String) - The name of the file that contains the slides you want to insert.
Index (Long) - The index number of the Slide object in the specified Slides collection you want to insert the new slides after.
Optional arguments
The following arguments are optional
SlideStart (Long) - The index number of the first Slide object in the Slides collection in the file denoted by FileName.
SlideEnd (Long) - The index number of the last Slide object in the Slides collection in the file denoted by FileName.
Item
Returns a single Slide object from the specified Slides collection.
Item (Index)
Index: The name or index number of the single Slide object in the collection to be returned.
Dim sld As Slide
Set sld = ActivePresentation.Slides(Index:=1)
Paste
Pastes the slides on the Clipboard into the Slides collection for the presentation. Specify where you want to insert the slides with the Index argument. Returns a SlideRange object that represents the pasted objects. Each pasted slide becomes a member of the specified Slides collection.
Use the ViewType property to set the view for a window before pasting the Clipboard contents into it. The following table shows what you can paste into each view.
Paste (Index)
Index: The index number of the slide that the slides on the Clipboard are to be pasted before. If this argument is omitted, the slides on the Clipboard are pasted after the last slide in the presentation.
Dim srePaste As SlideRange
Set srePaste = ActivePresentation.Slides.Paste()
Range
Returns a SlideRange object that represents a subset of the slides in a Slides collection.
Although you can use the Range method to return any number of shapes or slides, it is simpler to use the Item method if you only want to return a single member of the collection. For example, Shapes(1) is simpler than Shapes.Range(1), and Slides(2) is simpler than Slides.Range(2). To specify an array of integers or strings for Index, you can use the Array function. For example, the following instruction returns two shapes specified by name. Dim myArray() As Variant, myRange As Object myArray = Array("Oval 4", "Rectangle 5") Set myRange = ActivePresentation.Slides(1).Shapes.Range(myArray)
Range (Index)
Index: The individual slides that are to be included in the range. Can be an Integer that specifies the index number of the slide, a String that specifies the name of the slide, or an array that contains either integers or strings. If this argument is omitted, the Range method returns all the objects in the specified collection.
Dim sreRange As SlideRange
Set sreRange = ActivePresentation.Slides.Range()