英文:
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
如果您想更改DashStyle
或Style
:
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
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论