开发者

Pie Chart Data Labels in Excel 2003 VBA

I've run into a very strange problem with data labels in pie charts on Excel 2003. I'll set the .Top or .Left property of a data label absolutely in VBA, but Excel will automatically move it to a different value. Why does this happen? How can I work around this? This problem does not exist in Excel 2007, it seems, from my testing. To see what I mean, try creating a pie chart with data labels in excel 2007, and run the following function on the chart:

Sub problemExample(xlcht As Excel.Chart)

With xlcht.SeriesCollection(1)

    For aSlice = 1 To .Points.Count
        .Points(aSlice).DataLabel.Top = 43
        Range("F" & (aSlice + 1)).Value = .Points(aSlice开发者_如何学运维).DataLabel.Top
        .Points(aSlice).DataLabel.Left = 38
        Range("G" & (aSlice + 1)).Value = .Points(aSlice).DataLabel.Left
    Next aSlice
End With
End Sub


The reason is that positions are quantized. The top, left, width, and height properties aren't a continuous spectrum of possible values, they can only be changed by fixed increments. If you pick something between these increments, excel will immediately round the property to the nearest incremental value.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜