Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 06-06-2015, 02:07 AM
JohnWilson JohnWilson is offline Power Point - Deleting Legend enteries via VBA Windows 7 64bit Power Point - Deleting Legend enteries via VBA Office 2010 32bit
Programmer
 
Join Date: Nov 2008
Location: UK
Posts: 1,914
JohnWilson has a spectacular aura aboutJohnWilson has a spectacular aura about
Default

This is "top of head" code so treat with care. Alco it may nor work if the chart is linked to Excel.



Code:
Sub DeleteZero()
Dim m As Integer
Dim a As Variant
Dim L As Integer
Dim ocht As Chart
Dim b_val As Boolean
Dim oshp As Shape
Dim osld As Slide
For Each osld In ActivePresentation.Slides
For Each oshp In osld.Shapes
If oshp.HasChart Then
Set ocht = oshp.Chart
If ocht.HasLegend Then
For m = ocht.SeriesCollection.Count To 1 Step -1
    a = ocht.SeriesCollection(m).Values
    For L = 1 To ocht.SeriesCollection(m).Points.Count
        If a(L) <> 0 Then b_val = True
    Next L
   If Not b_val Then ocht.Legend.LegendEntries(m).Delete
   b_val = False
Next m
End If 'legend
End If ' chart
Next oshp
Next osld
End Sub
__________________
Microsoft PowerPoint MVP 2007-2023
Free Advanced PowerPoint Tips and Tutorials
Reply With Quote
  #2  
Old 06-06-2015, 01:12 PM
PowerPoint_VBA PowerPoint_VBA is offline Power Point - Deleting Legend enteries via VBA Windows 8 Power Point - Deleting Legend enteries via VBA Office 2010 32bit
Novice
Power Point - Deleting Legend enteries via VBA
 
Join Date: Jun 2015
Posts: 3
PowerPoint_VBA is on a distinguished road
Default

Thank you very much!

It is almost working. However I found a way in which power point charts are really misleading (attached file).

As you can see your macro works great on second slide, but on first it is mislead.
It's about legend order. On first slide it's "upside down" in excel meaning, on second one it's ok.

On first slide it is counting the opposite way (it should left "e" which is 5th from the beggining, instead it does not delete "l" which is 5th but from the end).

So to make it automatic, macro need to check the order. If the order is "upside down" it should take "upside down" legend entry and delete it .



Changing:
Code:
If Not b_val Then ocht.Legend.LegendEntries(m).Delete
Into:

Code:
If <Legend Enteries has appropriate order> Then

If Not b_val Then ocht.Legend.LegendEntries(m).Delete

Else

If Not b_val Then ocht.Legend.LegendEntries(ocht.SeriesCollection.Count - m + 1).Delete

End if
Do you have and idea, how to check Legend Order?


Of course it is possible to change Legend into "under chart" in each before starting macro, but then on some macro should reverse it and on some not so it would be difficult this way .
Attached Files
File Type: pptx Macro_legends_test.pptx (80.3 KB, 15 views)
Reply With Quote
Reply

Tags
powerpoint macro

Thread Tools
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Last Post
can power point LINK to embedded object in power point ? johnseito PowerPoint 0 05-24-2014 04:31 AM
Power Point - Deleting Legend enteries via VBA Power Point and Flash Paincho PowerPoint 1 06-27-2011 08:07 AM
Microsoft Power Point 2004 to Office Power Point 2007 chuff PowerPoint 0 03-20-2011 01:23 PM
Power Point on the Web Carthalion PowerPoint 0 03-03-2010 09:59 AM
power point ladonna12 PowerPoint 2 02-16-2009 09:34 AM

Other Forums: Access Forums

All times are GMT -7. The time now is 11:23 AM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2026, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2026 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft