如何用vba设置图表的坐标轴的刻度线类型和刻度线标签的位置?

图表的坐标轴刻度线可以有主刻度线和次刻度线,在VBA中可以用Axis对象的MajorTickMark属性和MinorTickMark属性分别表示主刻度线和次刻度线。

另外还可以用Axis对象的TickLabelPosition属性设置坐标轴的刻度线标签的位置。

有了以上的知识可以使用如下的vba代码设置图表的横纵坐标轴的刻度线类型和刻度线标签的位置:

Sub QQ1722187970()
    '创建内嵌的图表
    Dim oChart As Chart
    Dim oWK As Worksheet
    Dim oAZ As Axis
    Set oWK = Sheet1
    Dim oChartObject As ChartObject
    Dim oSeries As Series
    Set oChartObject = oWK.ChartObjects(1)
    Set oChart = oChartObject.Chart
    '对整个图表进行设置
    With oChart
        '设置纵坐标
        Set oAZ = .Axes(xlValue, xlPrimary)
        With oAZ
            .MajorTickMark = xlTickMarkOutside
            .MinorTickMark  = xlTickMarkNone
            .TickLabelPosition = xlTickLabelPositionNextToAxis
        End With
        '设置横坐标
        Set oAZ = .Axes(xlCategory, xlPrimary)
        With oAZ
             .MajorTickMark = xlTickMarkOutside
             .MinorTickMark = xlTickMarkNone
            .TickLabelPosition = xlTickLabelPositionNextToAxis
        End With
    End With
End Sub

 

       

发表评论