我可以翻译这句话为:如何在VBA中确定图表轴上设置的线条颜色类型?

huangapple go评论117阅读模式
英文:

How can I determine the type of line color set on a chartaxis in VBA?

问题

如何检查图表轴线的颜色设置是实线、渐变、自动或无线(VBA)

我尝试过这个,但似乎不起作用

ax.AxisLine.Format.Line.Style = msoLineSolid

你能修改代码的这部分吗?

英文:

How to check if a chartaxis line color is set solid line or gradient or automatic or no line on VBA

I tried this but does not seem to work

ax.AxisLine.Format.Line.Style = msoLineSolid

Can you modify this part of the code?

答案1

得分: 1

如果您想更改DashStyleStyle

Sub CheckChartAxisLineStyle()
    Dim ch As ChartObject
    Dim ax As Axis
    
    Set ch = ActiveSheet.ChartObjects(1)
    Set ax = ch.Chart.Axes(xlCategory) ' 将xlCategory更改为xlValue以用于数值轴
    
    With ax.Format.Line
        .Weight = 10
        .DashStyle = msoLineDashDotDot
        .DashStyle = msoLineSolid
        .DashStyle = msoLineSquareDot
    End With
    Debug.Print ax.Format.Line.Style '1
    Debug.Print ax.Format.Line.DashStyle '2
    ax.Format.Line.Style = msoLineThickBetweenThin
    
End Sub

有关DashStyle的详细信息,请参阅此处的文档,有关Style的详细信息,请参阅此处的文档

附注:您可能不希望将.Weight设置为10,这只是示例用途 :p

英文:

If you're looking to change the DashStyle or the Style :

Sub CheckChartAxisLineStyle()
    Dim ch As ChartObject
    Dim ax As Axis
    
    Set ch = ActiveSheet.ChartObjects(1)
    Set ax = ch.Chart.Axes(xlCategory) ' Change xlCategory to xlValue for value axis
    
    With ax.Format.Line
        .Weight = 10
        .DashStyle = msoLineDashDotDot
        .DashStyle = msoLineSolid
        .DashStyle = msoLineSquareDot
    End With
    Debug.Print ax.Format.Line.Style '1
    Debug.Print ax.Format.Line.DashStyle '2
    ax.Format.Line.Style = msoLineThickBetweenThin
    
End Sub 

For the DashStyle see documentation here and for the Style see documentation here

P.S. You probably don't want the .Weight at 10, that's just for example purposes :p

答案2

得分: 0

你可以像这样获取轴的样式:

charts("Chart1").Axes(xlPrimary).Format.Line.Style

.Axes 的参数指定你想要访问的轴的类型。需要使用 XlAxisType。你可以在这里了解更多信息:
XlAxisType

英文:

You can get the axis style like this:

charts("Chart1").Axes(xlPrimary).Format.Line.Style

The parameter for .Axes specifies which type of axes you want to access. A `XlAxisType' is needed. You can read about them here:
XlAxisType

huangapple
  • 本文由 发表于 2023年5月25日 14:10:19
  • 转载请务必保留本文链接:https://go.coder-hub.com/76329371.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定