我意识到您可以使用以下命令在VBA中设置图形的轴
.MaximumScale =
.MinimumScale =
有没有办法获取轴值?
我之所以这样问,是因为这样可以更轻松地自动化获取图表轴,然后向其中添加一个月的过程(无需将图形轴设置为自动)。
聚苯乙烯
我记录了一个更改轴日期的宏,它将日期值设置为40148或41609之类的数字。这是什么?
尝试逐步浏览以下代码段。它显示了如何查找Y轴值以及如何对其进行更改。看到里面的一些评论。
将图表嵌入工作表中的第一次尝试
Sub test_chart()
'get the chart for activesheet
Dim myCHR As Chart
Set myCHR = ActiveSheet.ChartObjects(1).Chart
'get Y axis of the chart
Dim myYA As Axis
Set myYA = myCHR.Axes(XlAxisType.xlValue)
'get the value
Debug.Print myYA.MaximumScale
Debug.Print myYA.MinimumScale
'the same in almost one line
With ActiveSheet.ChartObjects(1).Chart.Axes(xlValue)
Debug.Print .MaximumScale
Debug.Print .MinimumScale
'change the value
.MaximumScale = 10
End With
End Sub
图表的第二次尝试是单独的工作表
Sub test_sheet_chart()
'get the chart for activesheet
Dim myCHR As Chart
Set myCHR = Sheets("All SIN 10 Pubs - Unique Users")
'get Y axis of the chart
Dim myYA As Axis
Set myYA = myCHR.Axes(XlAxisType.xlValue)
'get the value
Debug.Print myYA.MaximumScale
Debug.Print myYA.MinimumScale
'the same in almost one line
With Sheets("All SIN 10 Pubs - Unique Users").Axes(xlValue)
Debug.Print .MaximumScale
Debug.Print .MinimumScale
'change the value
.MaximumScale = 10
End With
End Sub
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句