Adding Shapes to Slides
This content is no longer actively maintained. It is provided as is, for anyone who may still be using these technologies, with no warranties or claims of accuracy with regard to the most recent product version or service release.
Typically, you use the Add method of a collection object to add an item to the collection. For example, to add a slide to a Microsoft® PowerPoint® presentation, you use the Presentation object's Slides collection's Add method. However, adding shapes to a slide is a little different. The PowerPoint object model provides a different method for each shape you can add to a slide. For example, the following sample inserts a new slide at the end of the current presentation and uses two methods of the Shapes collection to add shapes to the slide. The AddTextEffect method is used to add a WordArt shape and the AddTextbox method is used to add a text box shape:
Sub AddTestSlideAndShapes()
' Illustrate how to add shapes to a slide and then
' center the shapes in relation to the slide and
' each other.
Dim sldNewSlide As PowerPoint.Slide
Dim shpCurrShape As PowerPoint.Shape
Dim lngSlideHeight As Long
Dim lngSlideWidth As Long
With ActivePresentation
' Determine height and width of slide.
With .PageSetup
lngSlideHeight = .SlideHeight
lngSlideWidth = .SlideWidth
End With
' Add new slide to end of presentation.
Set sldNewSlide = .Slides.Add(.Slides.Count + 1, ppLayoutBlank)
With sldNewSlide
' Specify a background color for the slide.
.ColorScheme = ActivePresentation.ColorSchemes(3)
' Add a WordArt shape by using the AddTextEffect method.
Set shpCurrShape = .Shapes.AddTextEffect(msoTextEffect16, _
"Familiar Quotations", "Tahoma", 42, msoFalse, msoFalse, 100, 100)
' Locate the WordArt shape at the middle of the slide, near the top.
With shpCurrShape
.Left = (lngSlideWidth - .Width) / 2
.Top = (lngSlideHeight - .Height) / 8
End With
' Add a Textbox shape to the slide and add text to the shape.
Set shpCurrShape = .Shapes _
.AddTextbox(msoTextOrientationHorizontal, 100, 100, 500, 500)
With shpCurrShape
With .TextFrame.TextRange
.Text = "'If not now, when? If not us, who?'" _
& vbCrLf & "'There is no time like the present.'" _
& vbCrLf & "'Ask not what your country can do for you, " _
& "ask what you can do for your country.'"
With .ParagraphFormat
.Alignment = ppAlignLeft
.Bullet = msoTrue
End With
With .Font
.Bold = msoTrue
.Name = "Tahoma"
.Size = 24
End With
End With
' Shrink the Textbox to match the text it now contains.
.Width = .TextFrame.TextRange.BoundWidth
.Height = .TextFrame.TextRange.BoundHeight
.Left = (lngSlideWidth - .Width) / 2
.Top = (lngSlideHeight - .Height) / 2
End With
End With
End With
End Sub
See Also
Working with Shapes on Slides | Positioning Shapes on Slides | Working with Text in a Shape