运行我在 Excel 2010 中创建的 vba 宏时出现运行时错误-2147467259 (80004005): Invalid parameter
。在设置 .CategoryType = xlTimeScale 后尝试设置 .majorUnitScale = xlMonths 时发生错误。尝试使用 .chartType = xlLineMarkers 创建图表
奇怪的是,当我在 Excel 2007 中运行此代码时,它可以完美运行并根据需要生成折线图。
以下是部分代码:
dim myChtObj as ChartObject
Set myChtObj = ActiveSheet.ChartObjects.Add(Left:=202, Width:=340, Top:=28,Height:=182)
With myChtObj.Chart
' remove extra series
Do Until .SeriesCollection.Count = 0
.SeriesCollection(1).Delete
Loop
.ChartType = xlLineMarkers
.HasTitle = True
.ChartTitle.Text = "Performance Trends"
.ChartTitle.Font.Size = 12
.ChartTitle.Font.Name = "Calibri"
.ChartTitle.Font.FontStyle = "Bold"
With .Axes(xlCategory)
.CategoryType = xlTimeScale
.BaseUnit = xlMonths
.MajorUnit = 2
.MajorUnitScale = xlMonths ' run-time error occurs here
.MinorUnit = 1
.MinorUnitScale = xlMonths
.TickLabels.NumberFormat = "mmm yy"
.TickLabels.Orientation = 45
End With
.....
End with
谢谢!