Supercharge your PowerPoint productivity with

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

Tell me about PPTools

Toggle a design grid on and off


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 and more

This will allow you to add or remove a design grid on a slide.
By editiing the values as shown below, you can change the spacing and color of the grid.

It's not a snap-to grid and you can't lock it in position, but if you accidentally move the gridlines, you can easily toggle them off and back on again.

Run Sub ToggleGrid to use the macros. It figures out whether the gridlines need to be added or removed, then does so.

Option Explicit
' Edit these two values to change the grid spacing in inches
Const dVspacing As Double = 0.25
Const dHspacing As Double = 0.25
' Edit these three values to change the RGB color of the grid lines
Const lGridColorRed As Long = 225
Const lGridColorGreen As Long = 225
Const lGridColorblue As Long = 225

Sub ToggleGrid()
    If Len(ActiveWindow.Selection.SlideRange(1).Tags("GRIDDED")) > 0 Then
        Call RemoveGrid
    Else
        Call CreateGrid
    End If
End Sub
Function CreateGrid()
' Creates gridlines
' Edit the values below to change spacing and color

    Dim oSh As Shape
    Dim oSl As Slide
    Dim x As Double

    Dim dBeginX As Double
    Dim dBeginY As Double
    Dim dEndX As Double
    Dim dEndY As Double

    ' these hold dVspacing and dHspacing converted to points
    Dim dVspace As Double
    Dim dHspace As Double

    dVspace = dVspacing * 72
    dHspace = dHspacing * 72

    dBeginX = 0
    dBeginY = 0
    dEndX = ActivePresentation.PageSetup.Slidewidth
    dEndY = ActivePresentation.PageSetup.Slideheight

    Set oSl = ActiveWindow.Selection.SlideRange(1)
    With oSl
        ' add vertical gridlines
        For dBeginX = 0 To ActivePresentation.PageSetup.Slidewidth
            Set oSh = oSl.Shapes.AddLine(dBeginX, dBeginY, dBeginX, dEndY)
            With oSh
                ' Change RGB value here:
                .Line.ForeColor.RGB = RGB(lGridColorRed, lGridColorGreen, lGridColorblue)
                Call .Tags.Add("GRIDLINE", "YES")
            End With
            dBeginX = dBeginX + dHspace
        Next
        ' add horizontal gridlines
        dBeginX = 0
        dBeginY = 0
        For dBeginY = 0 To ActivePresentation.PageSetup.Slideheight
            Set oSh = oSl.Shapes.AddLine(dBeginX, dBeginY, dEndX, dBeginY)
            With oSh
                ' Change RGB value here:
                .Line.ForeColor.RGB = RGB(225, 225, 225)
                Call .Tags.Add("GRIDLINE", "YES")
            End With
            dBeginY = dBeginY + dVspace
        Next
        ' Mark the slide so we know that it's gridded
        Call .Tags.Add("GRIDDED", "YES")
    End With

End Function

Function RemoveGrid()
    Dim oSh As Shape
    Dim x As Long
    For x = ActiveWindow.Selection.SlideRange(1).Shapes.Count To 1 Step -1
        Set oSh = ActiveWindow.Selection.SlideRange(1).Shapes(x)
        If Len(oSh.Tags("GRIDLINE")) > 0 Then
            oSh.Delete
        End If
    Next
    ' Mark the slide so we know that it's gridded
    ActiveWindow.Selection.SlideRange(1).Tags.Delete ("GRIDDED")

End Function

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


Desktop Publishing Forum Visit http://DesktopPublishingForum.com For intelligent and lively discusssion of print and web publishing.



Supercharge your PPT Productivity with PPTools


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

Toggle a design grid on and off
http://www.pptfaq.com/FAQ00742.htm
Last update 09 September, 2006