获取图表轴值

时间:2014-01-14 11:20:54

标签: vba excel-vba excel

我意识到你可以使用

在VBA中设置图形的轴
.MaximumScale = 
.MinimumScale = 

有没有办法获得轴值?

我问这个是因为它可以更容易地自动化获取图表轴的过程,然后为其添加一个月(不将图形轴设置为自动)。

P.S。

我录制了一个更改轴日期的宏,并将日期值设置为 40148 41609 之类的数字。这是什么?

1 个答案:

答案 0 :(得分:1)

尝试逐步执行以下代码段。它显示了如何查找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
相关问题