Bryan Hamilton
Bryan Hamilton

Reputation: 27

VBA macro to increment rotation of selected shape/picture in powerpoint

Basically, I am not much of a programmer and do a lot of drawing and diagramming in PowerPoint for education purposes. I currently use PowerPoint 2016. To increase my workflow speed, I map keyboard shortcuts to macro keys on my keyboard so I get the functionality just by hitting a key on the keyboard.

I am trying to find a macro that I can link to a keyboard shortcut allowing me to increment the rotation of the currently selected shape to … let’s say 2 degrees each time I hit the shortcut.

I'm new to ppt vba. After doing some research so far here is what I came up with. But it doesn't seem to be working.

Public Sub RotateCW2()
  Dim shp As Shape

    Set shp = ActiveWindow.Selection.ShapeRange(1)
    shp.Rotate = shp.Rotate + 2  

End Sub

Appreciate the help!

Upvotes: 0

Views: 7553

Answers (4)

Bryan Hamilton
Bryan Hamilton

Reputation: 27

After mix and matching things arround, I think this one is working.

Sub Rotate()

      With ActiveWindow.Selection.ShapeRange
        .IncrementRotation 2
      End With

End Sub

and it works as intended. Thanks guys for your answers.

Upvotes: 1

user9298223
user9298223

Reputation:

The Shape Object has a series of Increment properties to choose from.

Note: Descriptions copied from MSDN

IncrementRotation( Increment )

"Specifies how far the shape is to be rotated horizontally, in degrees. A positive value rotates the shape clockwise; a negative value rotates it counterclockwise."

IncrementRotationX( Increment )

"Specifies how much (in degrees) the rotation of the shape around the x-axis is to be changed. Can be a value from ? 90 through 90. A positive value tilts the shape up; a negative value tilts it down."

IncrementRotationY( Increment )

"Specifies how much (in degrees) the rotation of the shape around the y-axis is to be changed. Can be a value from ? 90 through 90. A positive value tilts the shape to the left; a negative value tilts it to the right."

Public Sub RotateCW2()
  Dim shp As Shape

    Set shp = ActiveWindow.Selection.ShapeRange(1)
    shp.Rotate = shp.IncrementRotation 2

End Sub

Upvotes: 0

Bryan Hamilton
Bryan Hamilton

Reputation: 27

From Thomas' answer I figured I might try this.

Public Sub RotateCW2()
  Dim shp As Shape

    Set shp = ActiveWindow.Selection.ShapeRange(1)
    shp.Rotate = shp.IncrementRotation(2)
End Sub

This time I get the error "Compole error: Expected Function or variable" and it highlights (.IncrementRotation).

Upvotes: 0

Steve Rindsberg
Steve Rindsberg

Reputation: 14809

You were almost there. Try this instead:

Public Sub RotateCW2()
  Dim shp As Shape

    Set shp = ActiveWindow.Selection.ShapeRange(1)
    shp.Rotation = shp.Rotation + 2  

End Sub

Upvotes: 0

Related Questions