我想创建一些贯穿每个工作表的VBA代码,以制作图表标题font size = 18
,图表轴font size = 16
,chart width = 6
和chart height = 12
。当前很难将字体大小放在循环中
获取错误:对象不支持此属性或方法
Sub ResizeCharts() 'Make all charts on active sheet uniform size.
Dim cht As ChartObject
For Each cht In ActiveSheet.ChartObjects
cht.Height = Application.InchesToPoints(6)
cht.Width = Application.InchesToPoints(12)
With cht.ActiveChart
With .ChartTitle
.Size = 18
End With
End With
Next
End Sub
答案 0 :(得分:3)
正如@BruceWayne所说,您想使用cht
对象并遍历工作表(如果要在所有工作表中绘制所有图表)
For Each Sht In Application.Worksheets
For Each cht In Sht.ChartObjects
cht.Height = Application.InchesToPoints(6)
cht.Width = Application.InchesToPoints(12)
cht.Chart.ChartTitle.Format.TextFrame2.TextRange.Font.Size = 18
next cht
Next Sht
End Sub