PDA

View Full Version : How to change pie chart to doughtnut chat for VBA Code



selva_235
08-04-2016, 02:40 AM
Hi,

I have worked PPT file so many pie charts available. If any possible to change the pie chart to doughtnut chart in vba code. And i cannot do doughtnut chart label values position in outside in the chart.

John Wilson
08-04-2016, 09:00 AM
This will change pie charts to doughnuts BUT there is no way to have data labels outside the doughnut.


Sub toDNut()
Dim osld As Slide
Dim oshp As Shape
On Error Resume Next
For Each osld In ActivePresentation.Slides
For Each oshp In osld.Shapes
If oshp.HasChart Then
Select Case oshp.Chart.ChartType
Case Is = xlPie, xlPieExploded ' you can add more pie types if needed
oshp.Chart.ChartType = xlDoughnut
Case Else
'do nothing
End Select
End If
Next oshp
Next osld
End Sub

selva_235
08-05-2016, 02:01 AM
Thanks so much for your help. And one more i do not need all the slides i need to change single and single slides and how to set doughnut hole size for this vba code.

John Wilson
08-05-2016, 10:27 AM
Sub toDNut()
Dim osld As Slide
Dim oshp As Shape
Dim ocht As Chart
On Error Resume Next
Set osld = ActiveWindow.Selection.SlideRange(1)
For Each oshp In osld.Shapes
If oshp.HasChart Then
Set ocht = oshp.Chart
Select Case ocht.ChartType
Case Is = xlPie, xlPieExploded ' you can add more pie types if needed
ocht.ChartType = xlDoughnut
Case Else
'do nothing
End Select
If ocht.ChartType = xlDoughnut Then ocht.ChartGroups(1).DoughnutHoleSize = 25 '%
End If
Next oshp
End Sub

selva_235
08-08-2016, 12:22 AM
Yeah, It's working,

Thanks you so much for your great help John :):):)!!!