我正在运行一个宏来调整我的绘图区域,以使所有图形在报表中均匀。但是,在调整绘图区域的大小时,图表数据表也会调整大小,并且数据表中行的标签将成为文本换行。如果我稍微手动调整绘图区域大小然后文本是固定的并且是自动调整并且不再包装文本以占用三行或四行,则此问题已得到解决。有任何解决这个问题的方法吗?这是我目前的代码。
Sub Color_Loop_Series()
Dim sht As Worksheet
Dim CurrentSheet As Worksheet
Dim cht As ChartObject
Dim ser As Series
For Each sht In ActiveWorkbook.Worksheets
For Each cht In sht.ChartObjects
cht.Activate
ActiveChart.ChartType = xlLineMarkers
ActiveChart.Legend.Position = xlLegendPositionBottom
ActiveChart.Legend.Font.Size = 9
ActiveChart.PlotArea.Select
Selection.Width = 380
Selection.Left = 11
Selection.Top = 3
Selection.Height = 250
ActiveChart.Axes(xlValue).AxisTitle.Position = xlAxisPositionLeft
ActiveChart.DataTable.Font.Size = 5.5
Next cht
Next sht
End Sub
答案 0 :(得分:0)
我可以在移动绘图区域时通过录制宏来使用Excel 2010复制问题。运行录制的宏时,数据表图例会调整大小并进行文本换行。我无法找到数据表图例的任何直接句柄,但确实发现.Left
和.InsideLeft
都会影响自动换行。
以下是您的代码,稍微修改以删除所有Active
语句。
Sub Color_Loop_Series()
Dim sht As Worksheet
Dim CurrentSheet As Worksheet
Dim cht As ChartObject
Dim ser As Series
For Each sht In ActiveWorkbook.Worksheets
For Each cht In sht.ChartObjects
With cht.Chart
.ChartType = xlLineMarkers
.Legend.Position = xlLegendPositionBottom
.Legend.Font.Size = 9
.DataTable.Font.Size = 5.5
.Axes(xlValue).AxisTitle.Position = xlAxisPositionLeft
End With
With cht.Chart.PlotArea
.Width = 380
.Height = 250
.Left = 11
.Top = 3
.InsideLeft = 80 '<- Adjust this value
End With
Next cht
Next sht
End Sub
使用.InsideLeft
不使用.InsideLeft