Article ID: 162102
Article Last Modified on 10/11/2006
Dim MySlide As Slide
When you were typing in the code, you probably noticed some interesting
things happen. After you hit the spacebar following the word as, a drop
down list of the available data types appeared on your screen. This is
just one of the ways the Visual Basic Editor makes programming a little
easier.
Dim Indicates to the Visual Basic Editor you are about to declare
a variable. There are several other methods available to
declare variables, but this article discusses only the Dim
method.
MySlide Is the name you provide the variable. It is a good idea to
give your variables meaningful descriptive names. X is an
example of a poor variable name. Meaningful names make your
code easier to read.
As Slide Specifies the type of data the variable will contain. In
this case, MySlide will have the data type Slide.
Set MySlide = ActivePresentation.Slides.Add(1, ppLayoutTitle)
This code adds a new slide to the active presentation. The slide
created uses the Title Only AutoLayout. Lets take a closer look at
this line of code.
Set MySlide Assigns an object reference to a variable or
property. Using Set makes it easier to refer
to that same object later in your code.
ActivePresentation Tells the Visual Basic Editor you are referring
to the presentation that is open in the active
window.
Add(1, ppLayoutTitle) Creates a new slide and adds it to the
collection of slides in the presentation.
The Add method takes two parameters:
The first parameter, the slide index, is the
number 1 in this case. The slide index is the
position where PowerPoint creates the slide.
When the index is set to 1, PowerPoint creates
the new slide at the beginning of the
presentation.
The second parameter specifies the type of
AutoLayout.
For more information about creating slides programmatically, search for
"Add Slides" using the Help menu.
Sub YourMacro ()
'
' Macro created 1/7/97 by You
'
Dim MySlide As Slide
Set MySlide = ActivePresentation.Slides.Add(1, ppLayoutTitle)
End Sub
NOTE: The text following ' apostrophe (on the same line) is a comment.
Comments are ignored by the Visual Basic Editor. They are added to the
code to make it easier to understand what is going on in the code.
ActiveWindow.ViewType = ppViewSlideSorter
This changes the presentation to slide sorter view. We are doing this
so we can select the entire slide, including the slide itself.
MySlide.Select
This code selects the slide that you created. MySlide is the object
reference that you created with the Dim statement.
With ActiveWindow.Selection.SlideRange
.FollowMasterBackground = msoFalse
.Background.Fill.PresetTextured msoTextureRecycledPaper
End With
These commands tell PowerPoint that this particular slide does not
follow the master, and then set the background preset texture to the
recycled paper.
ActiveWindow.Selection.SlideRange.FollowMasterBackground = msoFalse
ActiveWindow.Selection.SlideRange.Background.Fill.PresetTextured _
msoTextureRecycledPaper
The underscore (_) in the second line is a continuation character. It tells
the Visual Basic Editor that you could not fit the specific command on
one line and are continuing the instruction on the next line.
MySlide.Shapes.Title.TextFrame.TextRange.Text = "Look What I Did!"
This command adds the text "Look What I Did!" into the title box of the
slide that you created.
With ActivePresentation.Slides.Range.SlideShowTransition
.AdvanceTime = 5
.EntryEffect = ppEffectCheckerboardAcross
End With
AdvanceTime Specifies how long (in seconds) a particular
slide is visible when running a slide show.
EntryEffect Specifies the slide transition effect that runs just
prior to the slide appearing.
ActivePresentation.SlideShowSettings.Run
This line of code starts the presentation as a slide show.
Sub YourMacro()
'
' Macro created <Date> by <You>
'
Dim MySlide As Slide
' Add a new slide to the presentation.
Set MySlide = ActivePresentation.Slides.Add(1, ppLayoutTitle)
' Change the presentation to slide sorter view.
ActiveWindow.ViewType = ppViewSlideSorter
' Select your slide.
MySlide.Select
' Apply a preset texture to the slide.
With ActiveWindow.Selection.SlideRange
.FollowMasterBackground = msoFalse
.Background.Fill.PresetTextured msoTextureRecycledPaper
End With
' Add text into title of the slide.
MySlide.Shapes.Title.TextFrame.TextRange.Text = "Look What I Did!"
' Set the slide timing and transition effect.
With ActivePresentation.Slides.Range.SlideShowTransition
.AdvanceTime = 5
.EntryEffect = ppEffectCheckerboardAcross
End With
' Start the slide show.
ActivePresentation.SlideShowSettings.Run
End Sub
176476 OFF: Office Assistant Not Answering Visual Basic Questions
163435 VBA: Programming Resources for Visual Basic for Applications
Additional query words: 97 8.00 kbmacro kbpptvba ppt8 vba vbe
Keywords: kbcode kbdtacode kbmacro kbprogramming KB162102