C H A P T E R 6 | Microsoft Office 97/Visual Basic Programmer's Guide |
Microsoft PowerPoint Objects |
When you start a PowerPoint session, you create an Application object. You use properties and methods of the Application object to control applicationwide attributes and behaviors, to control the appearance of the application window, and to get to the rest of the PowerPoint object model.
Note The following properties of the Application object can be used without the Application object qualifier: ActivePresentation, ActiveWindow, AddIns, Assistant, CommandBars, Presentations, SlideShowWindows, and Windows. All other properties and methods must have the object qualifier. For example, both of the following lines of code are valid.
Application.ActivePresentation.PrintOut
ActivePresentation.PrintOut
However, you cannot omit the object qualifier from the following line.
Application.Quit
Returning the Application Object
From code running in PowerPoint, you can use the Application
keyword alone to return the PowerPoint Application object.
The following example sets the left position for the application
window.
Application.Left = 30
If you set an object variable to the Application object, declare it as PowerPoint.Application. The following example sets an object variable to the PowerPoint Application object.
Dim appPPT As PowerPoint.Application
Set appPPT = Application
You can also use the Application property of any PowerPoint object to return the PowerPoint Application object. This is useful for returning the PowerPoint Application object from a PowerPoint presentation embedded in a document created in another application. The following example, when run from Microsoft Excel, sets an object variable to the PowerPoint Application object. Shape one on worksheet one must be an embedded PowerPoint presentation.
Dim appPPT As PowerPoint.Application
Set embeddedPres = Worksheets(1).Shapes(1)
embeddedPres.OLEFormat.Activate
Set appPPT = embeddedPres.OLEFormat.Object.Object.Application
Controlling the Appearance of the Application
Window
You can use properties and methods of the Application object
to control the appearance of the application window. The following
table shows which properties and methods control which aspects
of the application window's appearance.
Note that most of these properties and methods can also be applied
to the DocumentWindow object to control the appearance
of the document window.
Controlling ApplicationWide Attributes
and Behavior
You can use other properties and methods of the Application
object to control applicationwide settings or behaviors,
as shown in the following table.
Getting to Presentations, Document Windows,
and Slide Show Windows
The properties of the Application object that you'll probably
use most provide access to objects that represent presentations,
document windows, slide show windows, and addins. Use the
Presentations property of the Application object
to return any open presentation, or use the ActivePresentation
property to return the active presentation. Use the AddIns
property to return any available addin (an addin is
a special type of presentation you use to assemble and distribute
custom features). Use the Windows property of the Application
object to return any open document window, or use the ActiveWindow
property to return the active document window. Use the SlideShowWindows
property to return an open slide show window.
Getting to Shared Office Object Models
Other properties of the Application object provide access
to objects that represent shared Office features, such as menus
and toolbars, file searching, the Visual Basic Editor, and the
Office Assistant. For more information about these properties,
see "Application Object" in Help.
You can use other properties of the Application object
to control applicationwide settings and behavior, as shown
in the following table.
When you open or create a file in PowerPoint, you create a Presentation
object. (You may notice that many properties and methods of the
Presentation object correspond to items on the File
menu.) You use properties and methods of the Presentation
object or its collection to open, create, save, and close files;
to control presentationwide attributes and behavior; and
to get to slides and masters in the presentation.
Returning the Presentation Object
Use the ActivePresentation property to return the presentation
that's displayed in the active window. The following example saves
the active presentation.
You can return any open presentation by using the syntax Presentations(index),
where index is the presentation's name or index
number. The following example adds a slide to the beginning of
Sample Presentation.
Use the Presentation property to return the presentation
that's currently displayed in the specified document window or
slide show window. The following example displays the name of
the slide show that's running in slide show window one.
To return a Presentation object that represents an embedded
presentation, use the Object property of the OLEFormat
object for the shape that contains the embedded presentation.
The following example sets an object variable to the embedded
presentation in shape three on slide one in the active presentation.
Opening an Existing Presentation
To open an existing presentation, use the Open method.
This method always applies to the Presentations collection,
which you return by using the Presentations property. The
following example opens the file Pres1.ppt and then displays the
presentation in slide sorter view.
Notice that the return value of the Open method is a Presentation
object that refers to the presentation that was just opened.
Tip The
file name in this example contains a path. If you don't include
a path, the file is assumed to be in the current folder. Not including
the path in the file name may cause a runtime error, because
as soon as the user makes a different folder the current folder,
Visual Basic can no longer find the file.
Creating a New Presentation
To create a new presentation, apply the Add method to the
Presentations collection. The following example creates
a new presentation.
The Add method returns the presentation that's just been
created. When you add a presentation, you can set an object variable
to the returned presentation so that you can refer to the new
presentation in your code. The following example creates a new
presentation and adds a slide to it.
To do this Use this property or method
Activate the PowerPoint application window
Activate method
Check to see whether the PowerPoint application window is active
Active property
Set or return text that appears in the title bar of the PowerPoint application window
Caption property
Set or return the size and position of the PowerPoint application window on the screen
Height, Left, Top, and Width properties
Set or return a value that controls whether the application window is visible. You must set this property to True when you create a PowerPoint Application object in another application if you want to be able to see PowerPoint on your screen.
Visible property
Set or return a value that controls whether the PowerPoint application window is maximized, minimized, or floating.
WindowState property
To do this Use this property or method
Return the name of the active printer
ActivePrinter property
Return the PowerPoint build number
Build property
Display a Help topic
Help method
Return the name of the operating system
OperatingSystem property
Return the path to the PowerPoint application.
Path property
Quit PowerPoint Quit method
Run a Visual Basic procedure
Run method
Return the PowerPoint version number
Version property
To return a reference to
Use this property
Office Assistant Assistant property
PowerPoint menus and toolbars
CommandBars property
File search FileSearch property (FileFind property on the MacIntosh)
Visual Basic Editor
VBE property
ActivePresentation.Save
Presentations("Sample Presentation").Slides.Add 1, 1
MsgBox SlideShowWindows(1).Presentation.Name
Dim embeddedPres As Presentation
Set embeddedPres = ActivePresentation.Slides(1).Shapes(3).OLEFormat.Object
Dim myPres As Presentation
Set myPres = Presentations.Open(FileName:="c:\My documents\pres1.ppt")
myPres.Windows(1).ViewType = ppViewSlideSorter
Presentations.Add
Dim myPres As Presentation
Set myPres = Presentations.Add
myPres.Slides.Add 1, ppLayoutTitle
Presentations.Add.SaveAs "Sales Report"
Presentations("Sales Report").Slides.Add 1, ppLayoutTitle
Importing a Presentation from a Word Outline
To create a presentation from a Word outline, use the PresentIt
method of the Word Document object. The following example,
run from Word, exports Presentation Outline.doc as a presentation.
Document.Open("C:\Presentation Outline.doc")PresentIt
Activating a Presentation
There's no Activate method for the Presentation
object. To activate a PowerPoint presentation, activate one of
the document windows in which the presentation appears. The following
example activates the first document window in which the Sales
Report presentation appears.
Presentations("Sales Report").Windows(1).Activate
Controlling Slide Numbering, Size, and
Orientation in a Presentation
Use the PageSetup property of the Presentation object
to return the PageSetup object. This object contains settings
for slide and notes page orientation, slide size and orientation,
and slide numbering. The following example sets all slides in
the active presentation to be 11 inches wide and 8.5 inches high
and sets the slide numbering for the presentation to start at
17.
With ActivePresentation.PageSetup
.SlideWidth = 11 * 72
.SlideHeight = 8.5 * 72
.FirstSlideNumber = 17
End With
Note that the values you specify for some of the properties of the PageSetup object can automatically set values for other properties in a commonsense way that mimics behavior in the Page Setup dialog box (File menu) in the user interface. For example, setting the SlideOrientation property will switch the values of the SlideHeight and SlideWidth properties, if appropriate. By the same token, explicitly setting the SlideWidth and SlideHeight properties automatically sets SlideSize to ppSlideSizeCustom and sets the SlideOrientation property to the appropriate value (based on whichever is greater slide width or height).
Getting a Consistent Look Throughout a
Presentation
You can use templates and masters to ensure a consistent look
throughout your presentation. Use the ApplyTemplate method
of the Presentation object to apply a design template to
the presentation.
ActivePresentation.ApplyTemplate "c:\templates\presentation designs\meadow.pot"
Note The
available color schemes change when you apply a template. If you've
added a standard color scheme to the presentation, it will be
lost when the ApplyTemplate method is applied.
Use the HandoutMaster, NotesMaster, SlideMaster,
or TitleMaster property
of the Presentation object to return a Master object
that represents a slide, notes, or handout master. You can apply
a background fill or color scheme to a master, add background
graphics or ActiveX controls to a master, or format the text styles
and layout of a master when you want to apply changes to all slides
based on that master rather than applying them to one slide at
a time. The following example sets the background fill for the
slide master for the active presentation.
ActivePresentation.SlideMaster.Background.Fill.PresetGradient _
msoGradientHorizontal, 1, msoGradientBrass
If you want a specific shape, such as a picture or an ActiveX control, to show up on all slides in a presentation, add it to the master. An ActiveX control on the master will respond to events during a slide show whenever you click the control, on any slide where it appears.
To make uniform changes to the text formatting in a presentation, use the TextStyles property of the Master object to return the TextStyles collection., This collection contains three TextStyle objects that represent the following: the style for title text, the style for body text, and the style for default text (text in AutoShapes). Each TextStyle object contains a TextFrame object that describes how text is placed within the textbounding box and a Ruler object that contains tab stops and outlineindent formatting information. Use the Levels property of the TextStyle object to return the TextStyleLevels collection. This collection contains outline text formatting information for the five available outline levels (for title text and default text, always use level one). The following example sets the font name, the font size, and the space after paragraphs for levelone body text on all the slides in the active presentation that are based on the master.
With ActivePresentation.SlideMaster.TextStyles(ppBodyStyle).Levels(1)
With .Font
.Name = "Arial"
.Size = 36
End With
With .ParagraphFormat
.LineRuleAfter = False
.SpaceAfter = 6
End With
End With
Note You
can set the title and body text styles to different values for
each master. The default text style doesn't apply to each individual
master but rather to the entire presentation.
Printing a Presentation
Use the PrintOut method of the Presentation object
to print a presentation, as shown in the following example.
To set print options before printing, use the properties and methods
of the PrintOptions object. Use the PrintOptions
property of the Presentation object to return the PrintOptions
object. The following example prints three collated copies of
the active presentation.
ActivePresentation.PrintOut
With ActivePresentation.PrintOptions
.NumberOfCopies = 3
.Collate = True
.Parent.PrintOut
End With
Note that the Parent property of the PrintOption object used in the preceding example returns the Presentation object.
Saving a Presentation
When you save a new presentation for the first time, or when you
want to save an existing presentation under a new name, use the
SaveAs method. The following example creates a new presentation,
adds a slide to it, and saves it under the name "Sample."
With Presentations.Add
.Slides.Add 1, ppLayoutTitle
.SaveAs "Sample"
End With
For subsequent saves, use the Save method. The following example saves the active presentation.
ActivePresentation.Save
Closing a Presentation
To close a presentation, use the Close method of the Presentation
object. If there are changes in any presentation, PowerPoint displays
a message asking whether you want to save changes. The following
example closes Pres1.ppt.
Presentations("pres1.ppt").Close
With Application.Presentations("pres1.ppt")
.Saved = True
.Close
End With
Setting Up and Running a Slide Show
Use the SlideShowSettings property of the Presentation
object to return the SlideShowSettings object, which lets
you set up and run the slide show for the presentation. The following
example sets the slide show in the active presentation to start
on slide two and end on slide four, to advance slides by using
the timings set in the first section, and to run in a continuous
loop until you press ESC. Finally, the example
runs the slide show.
With ActivePresentation.SlideShowSettings
.StartingSlide = 2
.EndingSlide = 4
.RangeType = ppShowSlideRange
.AdvanceMode = ppSlideShowUseSlideTimings
.LoopUntilStopped = True
.Run
End With
Getting to the Slides in a Presentation
Use the Slides property of the Presentation object
to get to the individual slides in a presentation and, from there,
to the graphics and text on the slides. The following section
discusses in detail how to work with slides.
There are three different objects in the PowerPoint object model
that represent slides: the Slides collection, which represents
all the slides in a presentation; the SlideRange collection,
which represents a subset of the slides in a presentation; and
the Slide object, which represents an individual slide.
In general, you use the Slides collection to create slides
and when you want to iterate through all the slides in a presentation;
you use the Slide object when you want to format or work
with a single slide; and you use the SlideRange collection
when you want to format or work with multiple slides the same
way you work with multiple slides in the user interface.
Returning the Slides Collection
To return the entire collection of slides in a presentation, use
the Slides property. The following example inserts slides
from the Clipboard at the end of the active presentation.
Returning the Slide Object
Use the Item method of the Slides collection to
return a single Slide object that you specify by name or
index number (because the Item method is the default method,
you can omit it from your code). The following example copies
the third slide in the active presentation to the Clipboard.
Because the index number of a particular slide can change when
you add, delete, or reorder slides, you may find it more reliable
to use the FindBySlideID property to specify a slide by
its slide ID number, a unique identifier that's assigned to a
slide when it's added to a presentation and that doesn't change
if you change the order of the slides (if you copy the slide into
another presentation, it's assigned a new ID number). The following
example copies the slide with the ID number 256 to the Clipboard.
Use the SlideID property of the Slide object to
get the slide's ID number. The following example adds a slide
to the active presentation and sets a variable to the slide ID
number for the new slide.
ActivePresentation.Slides.Paste
ActivePresentation.Slides(3).Copy
ActivePresentation.Slides.FindBySlideID(256).Copy
Dim newSlideID As Long
newSlideID = ActivePresentation.Slides.Add(1, ppLayoutTitleOnly).SlideID
To return the slide that's currently displayed in the specified document window or slide show window view, use the Slide property of the View object for the window. The following example copies the slide that's currently displayed in window two to the Clipboard.
Windows(2).View.Slide.Copy
To return a slide within the selection, use Selection.SlideRange(index), where index is the slide's name or index number. The following example sets the layout for slide one in the selection in the active window, assuming that the selection contains at least one slide.
ActiveWindow.Selection.SlideRange(1).Layout = ppLayoutTitle
Returning the SlideRange Object
Use Slides.Range(index), where index
is either the slide's name or index number or an array of slide
index names or slide index numbers, to return a SlideRange
object from the Slides collection. The following example
sets the background fill for slides one and three in the active
presentation.
With ActivePresentation.Slides.Range(Array(1, 3))
.FollowMasterBackground = False
.Background.Fill.PresetGradient msoGradientHorizontal, 1, msoGradientLateSunset
End With
Adding a Slide
Use the Add method of the Slides collection to create
a new slide and add it to the presentation. The following example
adds a title slide to the beginning of the active presentation.
ActivePresentation.Slides.Add 1, ppLayoutTitleOnly
Inserting Slides from a Word Outline
To insert slides based on a Word outline, use the InsertFromFile
method. The following example inserts the outline in Presentation
Outline.doc as slides after slide three in the active presentation.
ActivePresentation.Slides.InsertFromFile FileName:="C:\Presentation Outline.doc", Index:=3
Setting the Slide Background and Color
Scheme
If you want to set the background fill or color scheme for all
the slides in a presentation, use the Background or ColorScheme
property of the Master object, as discussed in the section
"Getting a Consistent Look Throughout a Presentation"
earlier in this chapter. If, however, you want to set the background
fill or color scheme for a particular slide or set of slides,
use the Background or ColorScheme property of the
Slide or SlideRange object.
To set the background fill for a slide or a set of slides, use
the Background property of the Slide or SlideRange
object to return the SlideRange object that represents
the slide background, and use the Fill property to return
the FillFormat object that represents the background fill.
You can then use the properties and methods of the FillFormat
object to set properties for the fill. The following example sets
a gradient fill for the background for slide one in the active
presentation.
With ActivePresentation.Slides(1)
.FollowMasterBackground = False
.Background.Fill.PresetGradient msoGradientHorizontal, 1, msoGradientDaybreak
End With
Note To
set the background for a slide independently of the slide master
background, set the FollowMasterBackground property for the slide
to False.
To set the color scheme for a slide or a set of slides, use the
ColorScheme property of the Slide or SlideRange
object to return the ColorScheme object that represents
the color scheme. You can then set the ColorScheme object
for the slide to another ColorScheme object, or you can
use the Colors method to edit individual colors in the
scheme. The following example sets the color scheme for slide
one in the active presentation to the third standard color scheme
(as counted from left to right and from top to bottom on the Standard
tab in the Color Scheme dialog box).
With ActivePresentation
.Slides(1).ColorScheme = .ColorSchemes(3)
End With
The following example uses the Colors method to access the title color in the color scheme for the active presentation and then uses the RGB property to access the redgreenblue (RGB) value for that color and set it to the RGB value for green that the RGB function generates.
ActivePresentation.Slides(1).ColorScheme.Colors(ppTitle).RGB = RGB(0, 255, 0)
Note The
set of available color schemes changes when you apply a template.
If you've added a standard color scheme to a presentation, this
color scheme will be lost when the ApplyTemplate method is applied.
Choosing the Slide Layout
When you add a slide to a presentation, you specify what layout
it should have by using the Layout argument
of the Add method. The following example adds a slide that
contains only a title placeholder to the beginning of the active
presentation.
You can check or change the layout of an existing slide by using
the Layout property. The following example changes the
layout of slide one in the active presentation to include a title
placeholder, a text placeholder, and a chart placeholder.
ActivePresentation.Slides.Add 1, ppLayoutTitleOnly
ActivePresentation.Slides(1).Layout = ppLayoutTextAndChart
Note When
you switch slide layouts, any placeholders that contain text or
an object remain on the slide, although they may have been repositioned
at the time of the switch.
Adding Objects to a Slide
You add objects (such as AutoShapes, OLE objects, and pictures)
to a slide by using one of the methods of the Shapes collection.
You return the Shapes collection, which represents the
entire drawing layer for a slide, using the Shapes property
of the Slide object. For information about how to create
and format objects on slides, see Chapter 10, "Shapes and the Drawing Layer." For information about controlling how
an object on a slide behaves during a slide show, see "Controlling How Objects Behave During a Slide Show" later in this chapter.
Changing Slide Order
To change a slide's position in the presentation, cut the slide
and then paste it in its new position. The following example moves
slide four in the active presentation and makes it slide six.
For this example to work, there must be at least six slides in
the presentation.
Setting Slide Transition Effects
The properties that control the transition effects for a slide
are stored in the SlideShowTransition object, which you
return by using the SlideShowTransition property of the
Slide or SlideRange object. The following example
specifies a Fast Strips DownLeft transition accompanied
by the Bass.wav sound for slide one in the active presentation.
The example also specifies that the slide advance automatically
five seconds after the previous animation or slide transition.
Note For
the timings you set for your slide transition to take effect,
the AdvanceMode property of the SlideShowSettings object must
be set to ppSlideShowUseSlideTimings.
Getting to the Speaker's Notes on the
Notes Page for a Slide
To gain access to the text in the notes area on the notes page
for a slide, use the NotesPage property to return a SlideRange
collection that represents the specified notes page. The following
example inserts text into placeholder two (the notes area) on
the notes page for slide one in the active presentation. (If you've
removed the slide image from the notes page, use Placeholders(1)
to return the notes area.)
The Selection object in PowerPoint represents the selection
in a document window. You use methods of the Selection
object to cut, copy, delete, or unselect the selection. You use
the Type property of the Selection object to figure
out what type of content is selected (slides, shapes, text, or
nothing at all), and you use the ShapeRange, SlideRange,
and TextRange properties to return only a certain type
of selected object.
Note Selectionbased
code is inefficient and is usually unnecessary. For example, you
can change the font properties of a text range directly without
having to select the text. If you rely on the macro recorder to
supply code for you, you should rewrite the code it generates
to be selectionindependent wherever possible.
Making a Selection
You can create a selection either manually or by applying the
Select method to the Shape, ShapeRange, Slide,
SlideRange, or TextRange object. The following example
selects shapes one and three on slide one in the active presentation.
Note You
can make a given selection programmatically only if you can make
that same selection manually in the active document window. For
example, if slide two is showing in the active document window,
you cannot select shapes on slide one. Similarly, you cannot make
a selection that's inappropriate to the current view in the active
document window. For example, if the active document window is
in slide sorter view, you cannot select a shape or text range
on an individual slide.
Returning the Selection Object
Use the Selection property of the DocumentWindow
object to return the selection. The following example cuts the
selection in the active window.
Returning Shapes, Text, or Slides in a
Selection
Use the ShapeRange property of the Selection object
to return the ShapeRange collection that includes all the
shapes in the selection. Use the Item method of the returned
ShapeRange object to return a single selected shape. The
following example cuts the third shape in the selection in the
active window.
Returning Selected Text
If only text is selected, use the TextRange property of
the Selection object to return a TextRange object
that represents the selected text. The following example applies
bold formatting to the first three characters in the selected
text in the active window.
To get to the text in a selected shape, do the following: return
the shape, use the TextFrame property to return the text
area in the shape, and then use the TextRange property
of the text frame to return the text in the shape. The following
example applies bold formatting to the first three characters
in the third shape in the selection in the active window
Returning Selected Slides
Use the SlideRange property of the Selection object
to return a SlideRange collection that includes all the
selected slides. The following example cuts the selected slides
in the active window.
When you open a file in PowerPoint, you simultaneously create
a Presentation object, which represents the contents of
the file; a DocumentWindow object, which represents the
interface between the user and the file in design mode; and the
View object, which represents a container for the contents
of the file in design mode.
When you start a slide show, you create a SlideShowWindow
object, which represents the interface between the user and the
file in run mode, and a SlideShowView object, which represents
a container for the contents of the file in run mode.
Understanding Presentations, Windows,
and Views
When you're running PowerPoint and you make changes to what you
see on the screen, you may be making changes to the Presentation
object, the DocumentWindow object, or the View object.
Returning the View and SlideShowView Objects
The View object represents the way information is displayed
in a document window. Use the View property of the DocumentWindow
object to return a View object. The following example sets
the document window to automatically adjust (zoom) to fit the
dimensions of the application window.
The SlideShowView object represents the way information
is displayed in the slide show window. Use the View property
of the SlideShowWindow object to return a SlideShowView
object. The following example runs a
slide show of the active presentation with shortcut keys disabled
(the Run method of the SlideShowSettings object
returns a SlideShowWindow object).
The following example sets the pointer color and pointer shape
for the second slide show that's currently running. (There can
be only one running slide show window per presentation, but there
can be multiple presentations running slide shows at the same
time.)
Navigating in a Slide Show in a Document
Window View or Slide Show Window View
Use the GotoSlide method of the View or SlideShowView
object to make a specific slide the active slide. The following
example makes slide three in the presentation in document window
one the active slide in the window.
Note that depending on what document view you're in, the term
"active slide" has slightly different meanings. In slide
view or note view, the active slide is the one that's currently
displayed in the window. In outline view or slide sorter view,
the active slide is the selected slide.
The following example advances the presentation in slide show
window one to the third slide.
You can also go to the first slide in a slide show by using the
First method or to the last slide by using the Last
method, or you can go to a custom slide show by using the GotoNamedShow
method. For more information about these methods, see the topics
for them in Help.
Pasting Clipboard Contents into a Document
Window View
Use the Paste
method to paste the contents of the Clipboard into the active
document window view. The following example copies the
selection in window one to the Clipboard and then copies it into
the view in window two. If the Clipboard contents cannot be pasted
into the view in window two for example, if you
try to paste a shape into slide sorter view this
example fails.
The following table shows what you can paste
into each view.
Pasted shapes will be added to the top of the z-order and won't replace selected shapes.
If one shape is selected, pasted text will be appended to the shape's text; if text is selected, pasted text will replace the selection; if anything else is selected, pasted text will be placed in it's own text frame.
If you paste a slide from the Clipboard, an image of the slide will be inserted onto the slide, master, or notes page as an embedded object.
A pasted slide will be inserted before the slide that contains the insertion point.
You cannot paste shapes into outline view.
A pasted slide will be inserted at the insertion point or after the last slide in the selection.
You cannot paste shapes or text into slide sorter view.
For information about setting the view for
a window before pasting the Clipboard contents into it,
see the following section.
Setting or Checking the View Type in a
Document Window
Use the Type property of the View object to see
what the active document view is, and use the ViewType
property of the DocumentWindow object to set the active
document view. The following example copies the selection in window
one to the Clipboard, makes sure that window one is in slide view,
and then copies the Clipboard contents into the view in window
two.
Returning the Slide That's Currently Showing in a Document Window View or Slide Show Window View
Use the Slide property to return the
Slide object that represents
the slide that's currently displayed in the specified slide show
window view or document window view.
The following example places on
the Clipboard a copy of the slide that's currently displayed in
slide show window one.
Tip If
the currently displayed slide is from an embedded presentation,
you can use the Parent property of the Slide object
returned by the Slide property to return the embedded presentation
that contains the slide. (The Presentation
property of the SlideShowWindow object or DocumentWindowobject returns the presentation in which the window was created,
not the embedded presentation.)
The entire drawing layer on a slide is represented by the Shapes
collection, and each object on a slide whether
it's a placeholder, AutoShape, or OLE object is
represented by a Shape object. Using properties and methods
of the Shapes collection, you can add objects to slides
and gain access to the individual objects on a slide. Using properties
and methods of the Shape object, you cancontrol the shape's
appearance, the text or OLE object it can contain, and the way
it behaves during a slide show. This section discusses the properties
and methods that control how a shape behaves during a slide show.
For information about the properties and methods that control
other attributes and behavior of shapes, see Chapter 10, "Shapes
and the Drawing Layer."
Controlling How a Shape Becomes Animated
During a Slide Show
The AnimationSettings object contains properties and methods
that control how and when a shape appears on a specific slide
during a slide show. The following example sets
shape two on slide one in the active presentation to become animated
automatically after five seconds.
When you work with the properties of the AnimationSettings
object, it's important to keep in mind how individual properties
work with each other and with the AdvanceMode property
of the SlideShowSettings object.
You won't see the effects of setting any properties of the AnimationSettings
object unless the specified shape is animated
that is, if the shape doesn't appear on the slide when the slide
is initially displayed during a slide show but appears later.
For a shape to be animated, the TextLevelEffect property
must be set to something other than ppAnimateLevelNone
and the Animate property must be set to True.
To put into effect animation timings, which determine when the
shape will appear on the slide during a slide show, you must not
only assign a number of seconds to the AdvanceTime property,
but you must also set the AdvanceMode property of the SlideShowSettings
object to ppAdvanceOnTime and set the AdvanceMode
property to ppSlideShowUseSlideTimings.
You can use the AfterEffect property to specify what happens
to a shape after it becomes animated. Obviously, unless a shape
gets animated and at least one other shape on the slide gets animated
after it, you won't see any of the aftereffects you set for the
shape. Additionally, unless the AfterEffect property is
set to ppAfterEffectDim, you won't see the effect of the
DimColor property setting.
Controlling How a Shape Responds to Mouse Actions During a Slide Show
The ActionSettings collection for a shape contains two
ActionSetting objects one that contains
properties and methods that control how a shape responds when
it's clicked during a slide show (corresponds to the settings
on the Mouse Click tab in the Action Settings dialog
box), and another that contains properties and methods that control
how a shape responds when the mouse pointer passes over it during
a slide show (corresponds to the settings on the Mouse Over
tab in the Action Settings dialog box). The following example
specifies that when shape three on slide one in the active presentation
is clicked during a slide show, the shape's color is momentarily
inverted, the Applause sound plays, and the slide show returns
to the first slide.
Note that different action settings are available for different
types of shapes (for example, you can use the ActionVerb
property only for OLE objects). Thus, for any given shape, you
should use only properties that correspond to the settings available
in the user interface when the shape is selected.
If you set a property of the ActionSetting
object but don't see the changes you made reflected in the slide
show, make sure that you've set the correct value for the Action
property, as shown in the following table.
Controlling How a Media Clip Plays During
a Slide Show
The PlaySettings object, which you return by using the
PlaySettings property of the AnimationSettings object,
contains properties and methods that control how and when a media
clip plays during a slide show. The following example inserts
a movie named "Clock.avi" into slide one in the active
presentation, sets it to play automatically after the previous
animation or slide transition, specifies that the slide show continue
while the movie plays, and specifies that the movie object be
hidden during a slide show except when it's playing.
Depending on whether you inserted the media clip as an OLE object
(using the Object command on the Insert menu, or
using the AddOLEObject method) or as a native media object
(using the Movies and Sounds menu or the AddMediaObject
method), different properties of the PlaySettings object
will apply to the clip. This mimics the way different options
are available for native media objects and OLE objects on the
Play Settings tab in the Custom Animation dialog
box (Slide Show menu).
The preferred way to insert media clips is as native media objects,
because native movies and sounds don't require the use of the
Windows Media Player and therefore respond faster when they're
clicked or activated. Most of the properties of the PlaySettings
object apply only to native media clips. The ActionVerb
property, which corresponds to the options listed in the Object
box on the PlaySettings tab in the Custom Animation
dialog box, is the only property of the PlaySettings object
that doesn't apply to native media objects.
To determine whether a particular media clip is a native media
object, check to see whether the value of the Type property
of the Shape object that contains the clip is msoMedia.
Use the MediaType property of the Shape object to
determine whether the clip is a sound or a movie. The following
example sets all native sound objects on slide one in the active
presentation to loop during a slide show until they're manually
stopped.
With ActivePresentation.Slides
.Item(4).Cut
.Paste 6
End With
With ActivePresentation.Slides(1).SlideShowTransition
.Speed = ppTransitionSpeedFast
.EntryEffect = ppEffectStripsDownLeft
.SoundEffect.ImportFromFile "c:\sndsys\bass.wav"
.AdvanceOnTime = True
.AdvanceTime = 5
End With
ActivePresentation.SlideShowSettings.AdvanceMode = _
ppSlideShowUseSlideTimings
ActivePresentation.Slides(1).NotesPage.Shapes.Placeholders(2) _
.TextFrame.TextRange.InsertAfter "Added Text"
ActivePresentation.Slides(1).Shapes.Range(Array(1, 3)).Select
ActiveWindow.Selection.Cut
ActiveWindow.Selection.ShapeRange(3).Cut
ActiveWindow.Selection.TextRange.Characters(1, 3).Font.Bold = True
ActiveWindow.Selection.ShapeRange(3).TextFrame.TextRange _
.Characters(1, 3).Font.Bold = True
ActiveWindow.Selection.SlideRange.Cut
Windows(1).View.ZoomToFit = True
ActivePresentation.SlideShowSettings.Run.View.AcceleratorsEnabled = False
With SlideShowWindows(2).View
.PointerColor.RGB = RGB(255, 0, 0)
.PointerType = ppSlideShowPointerPen
End With
Windows(1).View.GotoSlide 3
SlideShowWindows(1).View.GotoSlide 3
Windows(1).Selection.Copy
Windows(2).View.Paste
Into this view
You can paste the following from the Clipboard
Slide view or notes page view
Shapes, text, or entire slides.
Outline view Text or entire slides.
Slide sorter view Entire slides.
Windows(1).Selection.Copy
With Windows(2)
.ViewType = ppViewSlide
.View.Paste
End With
SlideShowWindows(1).View.Slide.Copy
With ActivePresentation.Slides(1).Shapes(2).AnimationSettings
.AdvanceMode = ppAdvanceOnTime
.AdvanceTime = 5
.TextLevelEffect = ppAnimateByAllLevels
.Animate = True
End With
With ActivePresentation.Slides(1).Shapes(3).ActionSettings(ppMouseClick)
.Action = ppActionFirstSlide
.SoundEffect.Name = "applause"
.AnimateAction = True
End With
If you use this property
To do this
Set the Action property to this value to put the change into effect
Hyperlink
Set properties for the hyperlink that will be followed in response to a mouse action on the shape during a slide show
ppActionHyperlink
Run
Return or set the name of the program to run in response to a mouse action on the shape during a slide show
ppActionRunProgram
Run
Return or set the name of the macro to be run in response to a mouse action on the shape during a slide show
ppActionRunMacro
ActionVerb
Set the OLE verb that will be invoked in response to a mouse action on the shape during a slide show
ppActionOLEVerb
SlideShowName
Set the name of the custom slide show that will be run in response to a mouse action on the shape during a slide show
ppActionNamedSlideShow
Set clockMovie = ActivePresentation.Slides(1).Shapes.AddMediaObject _
(FileName:="C:\WINNT\clock.avi", Left:=20, Top:=20)
With clockMovie.AnimationSettings.PlaySettings
.PlayOnEntry = True
.PauseAnimation = False
.HideWhileNotPlaying = True
End With
Dim so As Shape
For Each so In ActivePresentation.Slides(1).Shapes
If so.Type = msoMedia Then
If so.MediaType = ppMediaTypeSound Then
so.AnimationSettings.PlaySettings.LoopUntilStopped = True
End If
End If
Next