调整工作表中每个图表中所有数据标签的宽度 [英] Resize width of all data labels in every chart in the worksheet

查看:509
本文介绍了调整工作表中每个图表中所有数据标签的宽度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试获取代码以从工作表的图表中调整所有数据标签中的宽度,但是我无法设法执行此操作。这里我有代码来应用一个数字格式,我想添加width属性(它只适用于Excel 2013):

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


推荐答案

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

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

这篇关于调整工作表中每个图表中所有数据标签的宽度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆