Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angular/30.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Excel 调整工作表中每个图表中所有数据标签的宽度_Excel_Vba - Fatal编程技术网

Excel 调整工作表中每个图表中所有数据标签的宽度

Excel 调整工作表中每个图表中所有数据标签的宽度,excel,vba,Excel,Vba,我试图让代码调整工作表图表中所有数据标签的宽度,但我无法做到这一点。这里我有应用数字格式的代码,我想在其中添加width属性(它仅对Excel 2013有效): 这是更改数据标签宽度大小的代码: ActiveChart.FullSeriesCollection(1).DataLabels.Select ActiveChart.FullSeriesCollection(1).Points(4).DataLabel.Select Selection.Width = 19 在这里,我最终找到了一个解

我试图让代码调整工作表图表中所有数据标签的宽度,但我无法做到这一点。这里我有应用数字格式的代码,我想在其中添加width属性(它仅对Excel 2013有效):

这是更改数据标签宽度大小的代码:

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

在这里,我最终找到了一个解决方案:

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

您使用的是什么版本的Excel?Autofit不适用于表格吗?我使用的是2013。我想这是唯一一家承认这项财产的公司。
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