adjusting PubPieSlice object with VBA

Zauberkind
2StarLounger
Posts: 133
Joined: 21 Oct 2011, 10:08

adjusting PubPieSlice object with VBA

Post by Zauberkind »

Greetings,
I have a PowerPoint slide with a "PubPieSlice" autoform on it. It's like a pie chart, but not data-driven. Turn it on its side, and it looks like PacMan :burga:
I can use the handles to adjust the angles in edit mode, using the ShapeRange.Adjustments.Item(1|2). Is there a way to change this in a running presentation using VBA?
TIA for any help or insight
Zk

User avatar
HansV
Administrator
Posts: 74155
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: adjusting PubPieSlice object with VBA

Post by HansV »

Create a macro that changes the Adjustments, e.g.

Code: Select all

Sub ManipulatePie()
    Dim sld As Slide
    Dim shp As Shape
    Set sld = ActivePresentation.Slides(1)
    Set shp = sld.Shapes(3)
    With shp
        .Adjustments(1) = 30 - .Adjustments(1)
        .Adjustments(2) = 120 - .Adjustments(1)
    End With
End Sub
This code will act on the 3rd shape on the 1st slide of the presentation.

In PowerPoint, select the shape.
On the Insert tab of the ribbon, click Action.
In the Mouse Click tab, select Macro, then select the macro name (ManipulatePie in my example).
Click OK.
Regards,
Hans

Zauberkind
2StarLounger
Posts: 133
Joined: 21 Oct 2011, 10:08

Re: adjusting PubPieSlice object with VBA

Post by Zauberkind »

Thanks, Hans, that seems to work just fine.
I couldn't find any documentation on that anywhere.
For anyone else who wants to do something similar(ly weird), here's what I found out:
Shape.Rotation is the clockwise offset angle in degrees of the whole shape from vertical;
Shape.Adjustment(1) is the ccw offset angle in degrees of the start of the shape;
Shape.Adjustment(2) is the ccw offset angle in degrees of the end of the shape;
The latter two use the 3 o'clock position of the disc as 0 degrees.
When the start and end coincide, the difference goes from 0 to 360 degrees.
Values > 180 degrees can be set, but are returned in the range 0 to -180 degrees.

Demo to show progression (Macro PieAction is the HotSpot Action for the shape):

Code: Select all

Sub PieAction(obj1 As Shape)
    With obj1
        Debug.Print "Before: A(1)="; .Adjustments(1), "A(2)="; .Adjustments(2),"Rotation="; .Rotation
        .Adjustments(1) = 30 + .Adjustments(1)
        Debug.Print "After: A(1)="; .Adjustments(1), "A(2)="; .Adjustments(2)
    End With ' obj1
End Sub ' PieAction
Cheers,
Zk