将它们排列成圆形ppt vba时旋转形状

时间:2016-04-01 04:23:20

标签: vba powerpoint-vba

我找到了一个很好的脚本来将对象(形状)排列成一个圆圈: Aligning Shapes in a Circle using VBA, Microsoft Community

Sub Test()
Call AlignShapesInCircle(720 / 2, 540 / 2, 100, ActiveWindow.Selection.ShapeRange)
End Sub
Function AlignShapesInCircle(x As Single, y As Single, r As Single, shprng As ShapeRange)
'x,y    = center point of the circle
'r      = radius of the circle
'shprng = the shape selection that needs to be arranged
Dim angle As Single
Dim currentangle As Single
Dim x1 As Single
Dim y1 As Single
Dim i As Integer
currentangle = 0
angle = 360 / shprng.count
For currentangle = 0 To 359 Step angle
    i = i + 1
    x1 = r * Cos(D2R(currentangle))
    y1 = r * Sin(D2R(currentangle))
    shprng(i).Left = x + x1
    shprng(i).Top = y + y1
Next
End Function
Function D2R(Degrees) As Double
    D2R = Degrees / 57.2957795130823
End Function

Function R2D(Radians) As Double
    R2D = 57.2957795130823 * Radians
End Function

现在我希望旋转形状,这样如果我使用箭头,则尖端将始终朝向中心显示。

我必须在这里引入一行:

shprng(i).Left = x + x1
shprng(i).Top = y + y1
shprng(i).Rotation = ???

我能找到合适公式的任何想法吗?

1 个答案:

答案 0 :(得分:0)

傻了 - 想通了 - 它比我想象的要容易。不需要任何令我害怕的SIN和COS - 只是:

shprng(i).Rotation =(360 /(shprng.Count))*(i - 1)