Excel VBA chart axis error: “Method 'ScaleType

2020-05-05 18:00发布

I have an assignment in an Excel VBA macro

axscty = ax.ScaleType

which gives the error: "Method 'ScaleType' of object 'Axis' failed". I found sources stating that it is a bug in Excel 2007. Others found the error when setting .ScaleType, e.g.,

.ScaleType = xlLinear

I have found the cause of the error: I have a secondary Y-axis with data series. If I assign those series to the primary Y-axis and remove the secondary axis, the error disappears.

Anyone knows how to avoid the error when there is a secondary Y-axis?

1条回答
叛逆
2楼-- · 2020-05-05 18:48

It looks like the following works (if you have any secondary axis or not):

ActiveChart.SetElement (msoElementPrimaryCategoryAxisLogScale)
ActiveChart.SetElement (msoElementPrimaryValueAxisLogScale)
ActiveChart.SetElement (msoElementSecondaryCategoryAxisLogScale)
ActiveChart.SetElement (msoElementSecondaryValueAxisLogScale)
查看更多
登录 后发表回答