Excel VBA chart axis error: "Method 'ScaleType' of object 'Axis' failed" when reading `.ScaleType`

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?

Upvotes: 0

Views: 2218

Answers (1)

m4s
m4s

Reputation: 43

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)

Upvotes: 1

Related Questions