PowerPoint VBA: Turning On/Off the Snap to Grid

This PowerPoint VBA macro toggles the snap-to-grid setting of an active presentation.

Macro Example

Sub ToggleSnapToGrid()

  With ActivePresentation
    .SnapToGrid = Not .SnapToGrid
  End With

End With

Description

Starts the With statement

Sub...

  With ActivePresentation

The 3rd line starts the With…End With statement.

This statement tells PowerPoint that following any code will apply to an active presentation.

[Application.]ActivePresentation

The Application.ActivePresentation property returns the active Presentation object.

obj-PowerPoint-Application-ActivePresentation

The ActivePresentation property is a member of the PowerPoint.Global class, so we can omit the Application property.

obj-PowerPoint-ActivePresentation

Toggles Snap to Grid Lines

The 4th line toggles the snap-to-grid setting.

Sub...

  With ActivePresentation
    .SnapToGrid = Not .SnapToGrid

Presentation.SnapToGrid

The Presentation.SnapToGrid property returns or sets whether to snap shapes to the grid-lines in a presentation.

obj-PowerPoint-Presentation-SnapToGrid

Not Operator

The Not operator switches a boolean value to its opposite.
If the Presentation.SnapToGrid property is True, then it will be False.
If the Presentation.SnapToGrid property is False, then it will be True.

Ends the With Structure

Sub...

  With ActivePresentation
    .SnapToGrid = Not .SnapToGrid
  End With

The 5th line ends the With…End With statement.

After the 5th line is evaluated, this macro ends.

Sub ToggleSnapToGrid()

  With ActivePresentation
    .SnapToGrid = Not .SnapToGrid
  End With

End With

Properties

http://www.relief.jp/itnote/archives/powerpoint-vba-snap-to-grid.php

Apply to

  • PowerPoint 2013
  • PowerPoint 2010
  • PowerPoint 2007