Supercharge your PowerPoint productivity with

Supercharge your PPT Productivity with PPTools - Click here to learn more.

Tell me about PPTools

Frame a slide with a rectangle


PPTools
Shape Styles brings the power of styles to PowerPoint. Apply complex formatting with a single click
Merge Excel, CSV or tab-delimited data into PowerPoint presentations to create certificates, awards presentations, personalized presentations and more
FixLinks prevents broken links when you distribute PowerPoint presentations
Optimizer saves disk space and bandwidth, shrinks your PowerPoint presentations to the right size for email, screenshow or printing
PPT2HTML gives you full control of PowerPoint HTML output, helps meet Section 508 accessibility requirements
Prep4PDF preserves interactivity in PowerPoint presentations when you convert to PDF
Image Export converts PowerPoint slides to JPG, PNG, GIF, WMF and more

Problem

You want to "frame" a slide or slides with a rectangle.

Solution

The FrameASlide subroutine below will add a rectangle of the line thickness you request to a single slide.
The other Subroutines call it to do their work, either on the current slide or on all slides in the current presentation.

Sub CurrentSlide()
   ' This subroutine calls FrameASlide and passes it
   ' the current active slide.
    Call FrameASlide(ActiveWindow.Selection.SlideRange(1))
End Sub

Sub AllSlides()
   ' This calls FrameASlide for each slide in the presentation
   Dim oSld as Slide
   For Each oSld in ActivePresentation.Slides
      Call FrameASlide(oSld)
   Next
End Sub

Sub FrameASlide(oSld as Slide)

    Dim sngLineWidth As Single
    Dim oFrameShape As Shape
    Dim sngSlideWidth As Single
    Dim sngSlideHeight As Single
    Dim oSld As Slide
    Dim sngOffset As Single

    ' EDIT:
    sngLineWidth = 2    ' frame outline thickness in points
    ' NO MORE EDITS

    sngOffset = sngLineWidth / 2

    With ActivePresentation.PageSetup
        sngSlideWidth = .SlideWidth
        sngSlideHeight = .SlideHeight
    End With

    With oSld
        Set oFrameShape = .Shapes.AddShape(msoShapeRectangle, _
            0 + sngOffset, _
            0 + sngOffset, _
             sngSlideWidth - sngOffset, _
             sngSlideHeight - sngOffset)
    End With

    With oFrameShape
        With .Line
            .Weight = sngLineWidth
            .ForeColor.RGB = RGB(0, 0, 0)   ' black
        End With
        With .Fill
            .Visible = msoFalse
        End With
    End With

End Sub

See How do I use VBA code in PowerPoint? to learn how to use this example code.


Page copy protected against web site content infringement by Copyscape Contents © 1995-2008 Stephen Rindsberg, Rindsberg Photography, Inc. and members of the MS PowerPoint MVP team. You may link to this page but any form of unauthorized reproduction of this page's contents is expressly forbidden.

Español    Deutsch    Français    Português    Italiano    Nederlands    Greek    Japanese    Korean    Chinese



Supercharge your PPT Productivity with PPTools


content authoring & site maintenance by
Friday, the automatic faq maker (logo)
Friday - The Automatic FAQ Maker

Frame a slide with a rectangle
http://www.pptfaq.com/FAQ00941.htm
Last update 12 May, 2008