Excel VBA chart axis error: “Method 'ScaleType

2020-05-05 18:01发布

问题:

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:

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)