VBA 宏以增加所选 shape/picture 在 powerpoint 中的旋转

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

基本上,我不是一个程序员,出于教育目的,我在 PowerPoint 中做了很多绘图和图表。我目前使用的是 PowerPoint 2016。为了提高我的工作流程速度,我将键盘快捷键映射到键盘上的宏键,这样我只需按下键盘上的一个键即可获得该功能。

我正在尝试找到一个我可以 link 到键盘快捷键的宏,允许我将当前所选形状的旋转增加到……比方说每次我按下快捷键时 2 度。

我是ppt新手vba。到目前为止,在做了一些研究之后,这就是我想出的。但是好像不行。

Public Sub RotateCW2()
  Dim shp As Shape

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

End Sub

感谢您的帮助!

你快到了。试试这个:

Public Sub RotateCW2()
  Dim shp As Shape

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

End Sub

形状对象有一系列 Increment 属性可供选择。

注意:从 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

根据 Thomas 的回答,我想我可以试试这个。

Public Sub RotateCW2()
  Dim shp As Shape

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

这次我收到错误 "Compole error: Expected Function or variable" 并突出显示 (.IncrementRotation)。

混搭之后,我觉得这个很管用。

Sub Rotate()

      With ActiveWindow.Selection.ShapeRange
        .IncrementRotation 2
      End With

End Sub

并且它按预期工作。谢谢你们的回答。