OfficeTips Home || VBA Section || General Section || Download Section || Privacy Policy Bookmark and Share

New Guides object in PowerPoint 2013

2013 has introduced a long requested feature - object model support for guides. You can now add, position and delete guides. The guides are available on the Presentation, CustomLayout and SlideMaster objects.

Each object has it's own collection of guides. Deleting the guides on the presentation object does not delete the guides on the SlideMaster or CustomLayouts. You will need to enumerate through all the objects to clear out all the guides.

Another thing to note is that if you create a guide at a location that already has a guide then a new guide will not be created. Instead PowerPoint will return a reference to the guide at that location and all edits performed will apply to that guide.

Supported versions: PowerPoint 2013

' --------------------------------------------------------------------------------
' Copyright ©1999-2018, Shyam Pillai, All Rights Reserved.
' --------------------------------------------------------------------------------
' You are free to use this code within your own applications, add-ins,
' documents etc but you are expressly forbidden from selling or 
' otherwise distributing this source code without prior consent.
' This includes both posting free demo projects made from this
' code as well as reproducing the code in text or html format.
' --------------------------------------------------------------------------------
 
Sub InsertNewGuides()
With ActivePresentation
    'Position is in points just as shapes
    With .Guides.Add(ppHorizontalGuide, 100)
        .Color.RGB = vbMagenta
    End With
 
    With .Guides.Add(ppVerticalGuide, 100)
        .Color.RGB = vbMagenta
    End With
 
    Dim I As Long
 
    Debug.Print "Total guides in the presentation: " & .Guides.Count
    For I = 1 To .Guides.Count
        Debug.Print "Added guide at : " & .Guides(I).Position & _
            " RGB color value: " & .Guides(I).Color.RGB & " Orientation: " & _
            IIf(.Guides(I).Orientation = ppHorizontalGuide, "Horizontal", "Verical")
    Next 
    'Guides can be assigned to slide masters
    With .Slides(1).Design.SlideMaster
        With .Guides.Add(ppHorizontalGuide, 200)
            .Color.RGB = vbGreen
        End With
        With .Guides.Add(ppVerticalGuide, 200)
            .Color.RGB = vbGreen
        End With
 
        Debug.Print "Total guides in the slidemaster: " & .Guides.Count
        For I = 1 To .Guides.Count
            Debug.Print "Added guide at : " & .Guides(I).Position & _
                " RGB color value: " & .Guides(I).Color.RGB & " Orientation: " & _
                IIf(.Guides(I).Orientation = ppHorizontalGuide, "Horizontal", _
                "Verical")
        Next
 
    End With 
    'Guides can be assigned to custom layouts
    With .Slides(1).CustomLayout
        With .Guides.Add(ppHorizontalGuide, 300)
            .Color.RGB = vbBlue
        End With
        Debug.Print "Total guides in the custom layout used by slide 1: " & .Guides.Count
        For I = 1 To .Guides.Count
            Debug.Print "Added guide at : " & .Guides(I).Position & _
                " RGB color value: " & .Guides(I).Color.RGB & " Orientation: " & _
                IIf(.Guides(I).Orientation = ppHorizontalGuide, "Horizontal", _
                "Verical")
        Next
    
    End With
    
End With
End Sub
 
Sub DeleteGuides()
Dim I As Long
'Delete Presentation level guides
With ActivePresentation
    For I = .Guides.Count To 1 Step -1
        .Guides(I).Delete
    Next
End With
'Delete guides on the design slidemaster used by slide 1
With ActivePresentation.Slides(1).Design.SlideMaster
    For I = .Guides.Count To 1 Step -1
        .Guides(I).Delete
    Next
End With
'Delete guides on the custom layout used by slide 1
With ActivePresentation.Slides(1).CustomLayout
    For I = .Guides.Count To 1 Step -1
        .Guides(I).Delete
    Next
End With
End Sub
 
 

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