Power Point Slide Objects


by Linda Quinn
Close Window

PowerPoint presentations have slides.
Slides contain the information presented in a presentation.
Presentations without slides are empty files, and they are not very useful.

A presentation can have one or many slides.

Declare a slide object
Dim slid1 as slide

You can add as many slide object variables as you want.


Set the slide variable to a new slide.
Dim prst1 as presentation
Dim sld1 as slide

Set prst1 = ActivePresentation
Set sld1 = prst1.slides.Add 1, ppLayoutBlank


The prst1 variable is used in this example because we are adding the slide to a specific presentation.

Slide Index
In the above example, we are adding a slide with an index of "1".
This will position of the slide at the beginning of the presentation.

If there are 5 slides, and we add a slide with an index of "3", then the new slide will be placed as the third slide and the rest of the slides after 3 will be renumbered.

The index number in the Add statement is useful for positioning the slide as it is created. However, since index numbers are reassigned as slides are added and removed, you should not count on index numbers to identify specific slides.

Layout
In addition to assigning an index, you must assign a Layout to a new slide.

In this example, we have used ppLayoutBlank. This will create a blank slide.

Other possible layouts include ppLayoutText, ppLayoutChart, ppLayouttextAndClipArt or ppLayoutObjectAndText.


Referencing a Existing Slide
Set sld1 = prst1.slides(1)

The same caveat applies to index numbers in slides as apply to index numbers in presentations.
It is better to use a slide's name instead of an index.


But slides only have names if you assign them.
Prst1.slides(1).name = "MySlide"
Set sld1 = prst1.slides("MySlide")


Naming a new slide
Set sld1 = prst1.slides.Add 3, ppLayoutBlank
sld1.Name = "MySlide"

This assigns the name MySlide to the slide we added.
The slide name or the slide index can be used to refer to the slide.

Set sld1 = prst1.Slides(3)
Set sld1 = prst1.Slides("MySlide")

Both of the these statement are the same.

The name will always stay the same.
The index may change if other slides are added or removed.
Therefore, it is better practice to refer to the name instead of the index.



Slide Properties
There are several properties that apply to slides that are useful for the VBA programmer.

Layout
This is the layout assigned to a new slide when it is created.
PowerPoint requires a layout to be assigned to any new slide.
You can use ppLayoutBlank if you don't want to use a layout.

sld1.Layout = ppLayoutChart


Name
This assigns a name to a slide.

sld1.Name = "MySlide"


SlideIndex
This property returns the index number of a slide.
This is a read-only value. You cannot change it.

x = sld1.SlideIndex

The value of x will be the index number.


SlideID
All slides have a unique ID. This is NOT the same as the slide index.

x = sld1.SlideID

The Slide ID is read-only.
You can't assign a SlideId value, you can only retreive the ID value.
In this example, x will contain the ID number.
Unlike an index number, the SlideID will never change.


SlideNumber
The slide number is the number that will appear on the lower-right corner of the slide when displayed.
This is a read-only value.

x = sld1.SlideNumber


Slide Methods

Copy
sld1.Copy
OR .slides(2).Copy
OR .slides("MySlide").Copy


Paste
sld1.Paste
OR sld1.Paste 4

In the above example, you can PASTE a slide to a specific position.
If a position is not specified, the slide will be pasted as the last slide of the presentation.


MoveTo
sld1.Moveto 5

Move the slide to the 5th position in the presentation.

Delete
sld1.Delete






=================================================================
This content was created by Linda Quinn of LQNet.

See http://www.lqnet.com for a great collection of articles on this and other topics.

=================================================================
Copyright © 2006-2008, LQ Systems,Inc. All rights reserved.


====================================================================
Want an expert to help with your project?    LQ Systems, Inc.   Business Solutions
====================================================================