How often have you encountered this - you need to
nudge the data label just that little bit left or top or down and you do
it manually and all hell breaks loose? It's a lot easier doing it
programmatically. This little snippet just shows you how easy it really
is to nudge the data label and get the position just right.
'
--------------------------------------------------------------------------------
' Copyright ©1999-2007, Shyam Pillai, All Rights Reserved.
'
--------------------------------------------------------------------------------
' You are free to use this code within your own applications, add-ins,
' documents etc but you are expressly forbidden from selling or
' otherwise distributing this source code without prior consent.
' This includes both posting free demo projects made from this
' code as well as reproducing the code in text or html format.
'
--------------------------------------------------------------------------------
Sub OffsetDataPoints()
Dim oChart As Chart
Dim x As Integer, y As Integer
' Set the reference to the Chart object.
Set oChart = ActivePresentation.Slides(1).Shapes(1).OLEFormat.Object
' Iterate thru each series
For x = 1 To oChart.SeriesCollection.Count
' And then thru each data point in the series
For y = 1 To oChart.SeriesCollection(x).Points.Count
With oChart.SeriesCollection(x)
' If the datapoint has a label...
If .Points(y).HasDataLabel Then
' Offset the label 10 points (unit of measurement) above
.Points(y).DataLabel.Top = _
.Points(y).DataLabel.Top - 10
End If
End With
Next y
Next x
' Update the graph and quit the graph application
oChart.Application.Update
oChart.Application.Quit
End Sub
|