2016-04-01 34 views
-1

我發現了一個偉大的劇本安排的對象(形狀)成一個圓圈的位置: Aligning Shapes in a Circle using VBA, Microsoft Community旋轉形狀安排他們入圈PPT VBA時

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 = ??? 

任何想法在那裏我能找到合適的公式?

回答

0

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

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