Resize width of all data labels in every chart in

2019-08-15 22:14发布

I'm trying to get the code to resize width in all data labels from the charts of a worksheet but I cannot manage to do it. Here I have the code to apply a number format and I'd want to add the width property to that (it's just valid for Excel 2013):

Sub FormatAllCharts()
Dim ChtObj As ChartObject
For Each ChtObj In ActiveSheet.ChartObjects
With ChtObj.Chart
   For i = 1 To .SeriesCollection.Count
         With .SeriesCollection(i)
         .ApplyDataLabels
         .DataLabels.NumberFormat = "0,0;-0,0;;"
         End With
   Next
End With
Next
End Sub

This is the code for changing the width size of data labels:

ActiveChart.FullSeriesCollection(1).DataLabels.Select
ActiveChart.FullSeriesCollection(1).Points(4).DataLabel.Select
Selection.Width = 19

1条回答
欢心
2楼-- · 2019-08-15 22:40

Here, I have eventually found a solution:

Sub FormatAllCharts()
Dim i As Long
Dim oChtObj As ChartObject

    For Each oChtObj In ActiveSheet.ChartObjects
        With oChtObj.Chart
            For i = 1 To .SeriesCollection.Count
                With .SeriesCollection(i)
                  .ApplyDataLabels
                  .DataLabels.NumberFormat = "0,0;-0,0;;"
                    Values_Array = .Values
                  For j = LBound(Values_Array, 1) To UBound(Values_Array, 1)
                     .Points(j).DataLabel.Width = 19
                  Next
                End With
            Next
        End With
    Next
End Sub
查看更多
登录 后发表回答