我有一个脚本来设置一些范围,然后创建一个图表。直到我得到“运行时错误'438':Object不支持此属性或方法”的.Axes(xlCategory, xlPrimary).Caption = "Time from Sent to Rec'd"之前,一切都进行得很顺利。
这是我的密码:
Sub CreateChart()
dim avgWS as worksheet: set avgWS = activesheet
...[code here, setting the ranges and such]....
''' TIME TO CREATE THE CHART!!
with avgws
Dim newChart As Chart
' Set newChart = Charts.Add
Set newChart = Charts.Add.Location(xlLocationAsObject, avgWS.name)
With newChart
.ChartType = xlLineMarkers
.SeriesCollection.NewSeries
With .SeriesCollection(1)
.name = chartName
.Values = thePeopleChartValues
End With
.SeriesCollection.NewSeries
With .SeriesCollection(2)
.name = avgWS.Cells(1, dayLimitCol).Value
.Values = dayLimitValues
End With
.SeriesCollection.NewSeries
With .SeriesCollection(3)
.name = avgWS.Cells(1, overalltheAvgCol).Value
.Values = theAverages
End With
.HasTitle = True
.Axes(xlCategory).CategoryType = xlCategoryScale
.SetElement (msoElementPrimaryValueAxisTitleRotated)
.Axes(xlCategory, xlPrimary).Caption = "Time from the Sent to Shares Rec'd" '''' ERROR HERE!!
.SetElement (msoElementPrimaryCategoryAxisTitleAdjacentToAxis)
.Axes(xlCategory).Caption = "the Date"
.SetElement (msoElementChartTitleCenteredOverlay)
.Axes(xlCategory).Caption = "='CY 2014-15B Averages'!R1C2"
.SetElement (msoElementLegendRightOverlay)
.SetElement (msoElementLegendBottom)
End With我只包含了图表部分,但是如果您想要/需要更多的代码,请告诉我。我有范围和这样的设置,那里没有错误。只有当我尝试创建.Captions时才会这样。如果我遍历代码,通过F8跳过三行.caption行,图表就会像I want....just一样创建,我如何设置这些want....just标题?宏记录器没有多大帮助(这就是我如何到达我现在的位置)。
编辑:嗯,如果我用
.Axes(xlCategory, xlPrimary).HasTitle = True
.Axes(xlCategory, xlPrimary).AxisTitle.Characters.Text = "whatever whatever"它将横轴标题设置为“任何东西”。我想我正在取得进步,但我想要的是垂直标题,而不是水平标题,我想不出怎么做。
发布于 2015-08-04 20:04:06
在开始格式化轴标题之前,创建它:
.Axes(xlCategory, xlPrimary).HasTitle = True然后,要访问标题,请确保遍历AxisTitle对象:
.Axes(xlCategory, xlPrimary).AxisTitle.Caption = ""然后使用
.Axes(xlCategory, xlPrimary).AxisTitle.Orientation = xlVertical希望这能有所帮助。
https://stackoverflow.com/questions/31817509
复制相似问题