View Single Post
 
Old 06-06-2015, 12:07 AM
PowerPoint_VBA PowerPoint_VBA is offline Windows 8 Office 2010 32bit
Novice
 
Join Date: Jun 2015
Posts: 3
PowerPoint_VBA is on a distinguished road
Default Power Point - Deleting Legend enteries via VBA

Hello,

I am preparing automization for data in excel and presentation. The last thing I struggle with is deleting unnecessary legend entries in power point.

I suppose I would be able to get rid of them in excel via VBA, but still it doesn't change anything because even if I do so it will not affect power point presentation. Power Point Charts are linked to excel, and as I checked: deleting legend enteries in Excel file will not affect linked charts in PowerPoint (checked on Office 2010).

What I would like to do is some macro which will check each slide, each chart. And if there is a blank data entry delete it's legend entry.

Here is how I would like to change my graphs:
Before
After


I think something like that will make it, however I do not know VBA for PowerPoint.

Code:
Sub MacroDeletingLegendEnteries()

Dim ppt As Presentation
Dim s As Slide
Dim ch As Chart

'Count from slide one to last slide
For i=1 to ppt.Slides.Count

	'Count from chart one to last chart on this slide
	For x=1 to <last chart on this slide>

		'Take any action only if chart has legend - there are some charts which don't need it
		If <chart has a legend> Then

			'Count from series 1 to last one
			For z=1 to <Number of data series on slide>
				
				'If the legend entry does not exist, then delete it legend entry on chart
				If <Data series z = 0 (there isn't any data on graph)> Then
					<Delete Legend entry number z>
				End If
			Next z

		End if
	
	Next x


Next i



End Sub

Thank you very much for any help with <> entries .
Reply With Quote