OfficeTips Home || VBA Section || General Section || Download Section || Privacy Policy

What is a Bounding Box in a shape's text range?

Consider a shape on the slide. The Top & Left properties of a shape give you the distance of shape within the slide from the top edge of the slide and the left edge of the slide respectively. The Height & Width properties provide you with the dimensions of the shape.

Now if this shape contains a text range then the text of the text range is contained within a invisible rectangle. This rectangle is the smallest perimeter that will surround the text in the text range and is called the bounding box. The bounding box maybe  larger than the parent shape within which it is contained. All positional/dimensional properties behave exactly identical to the properties of the parent shape though BoundTop, BoundLeft, BoundHeight & BoundWidth are read only properties.

BoundTop - Distance of the Topmost point of the invisible bounding box of the test range from the top edge of the slide
BoundLeft - Distance of the Leftmost point of the invisible bounding box of the text range from the left edge of the slide.

Note that in both the cases (shape & text range) the distances are relative the Top/left edge of the slide.


This code snippet adds a Agenda slide to the beginning of presentation and picks up slide titles in the active presentation and assigns hyperlinks to them. You would have to resize the font size after the links are created if there are a large number of slides -- that is left as exercise.

Sub AgendaLinks()
    Dim oSld As Slide
    Dim oShp As Shape
    Dim oAgenda As TextRange
    Dim x As Integer
    ' Add a slide to the beginning of presentation
    ActivePresentation.Slides.Add 1, ppLayoutText
    With ActivePresentation.Slides(1)
        .Shapes(1).TextFrame.TextRange = "Agenda Slide"
        Set oAgenda = .Shapes(2).TextFrame.TextRange
    End With

    oAgenda = ""

    For Each oSld In ActivePresentation.Slides
        ' Does the slide have title placeholder?
        If oSld.Shapes.HasTitle Then
            ' Get the reference to the title shape on the slide
            Set oShp = oSld.Shapes.Title
            ' Check if the placeholder has  any text in it.
            If oShp.TextFrame.TextRange.Text = "" Then
                oAgenda = oAgenda & "Slide " & oSld.SlideIndex & Chr(13)
                oAgenda = oAgenda & oShp.TextFrame.TextRange.Text & Chr(13)
            End If
            oAgenda = oAgenda & "Slide " & oSld.SlideIndex & Chr(13)
        End If

    Next oSld

    ' Add hyperlinks to the titles.
    For x = 1 To oAgenda.Sentences.Count
        Set oSld = ActivePresentation.Slides(x)
        With oAgenda.Sentences(x) _

            .Address = ""
            ' Hyperlink - Slide ID, Slide Index, Slide Title
            .SubAddress = oSld.SlideID & "," & _
                          oSld.SlideIndex & "," & _
        End With
    Next x
    ' Delete the first one because it points to the agenda slide.
End Sub







Copyright 1999-2014 (c) Shyam Pillai. All rights reserved.