Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/excel/27.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/loops/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Vba Can';设置图表轴标题(.caption)_Vba_Excel_Charts - Fatal编程技术网

Vba Can';设置图表轴标题(.caption)

Vba Can';设置图表轴标题(.caption),vba,excel,charts,Vba,Excel,Charts,我有一个脚本设置一些范围,然后创建一个图表。在.Axes(xlCategory,xlPrimary)之前一切都很顺利。Caption=“从发送到记录的时间”我在那里得到错误“运行时错误'438':对象不支持此属性或方法” 这是我的密码: Sub CreateChart() dim avgWS as worksheet: set avgWS = activesheet ...[code here, setting the ranges and such].... ''' TIM

我有一个脚本设置一些范围,然后创建一个图表。在
.Axes(xlCategory,xlPrimary)之前一切都很顺利。Caption=“从发送到记录的时间”
我在那里得到错误“运行时错误'438':对象不支持此属性或方法”

这是我的密码:

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
我只包含了图表部分,但是如果您想要/需要更多的代码,请告诉我。我有范围和这样的设置,没有错误。只有当我尝试创建
.caption
时,才会出现这种情况。如果我通过F8遍历代码并跳过三行
.caption
,图表就会按我所希望的那样创建…我该如何设置这些轴标题?宏记录器帮不了什么忙(这就是我现在的处境)

编辑:嗯,如果我使用

.Axes(xlCategory, xlPrimary).HasTitle = True
.Axes(xlCategory, xlPrimary).AxisTitle.Characters.Text = "whatever whatever"

它将水平轴标题设置为“任意”。我想我正在取得进展,但我希望它是垂直标题,而不是水平标题,并且不知道如何进行。在开始格式化轴标题之前,请创建它:

.Axes(xlCategory, xlPrimary).HasTitle = True
然后,要访问标题,请确保浏览AxisTitle对象:

.Axes(xlCategory, xlPrimary).AxisTitle.Caption = ""
然后使用

.Axes(xlCategory, xlPrimary).AxisTitle.Orientation = xlVertical

希望能有帮助。

啊,是的!非常感谢。只需注意,使用
xlVertical
将文本放在X轴上,但不是垂直旋转,而是将文本“混在一起”。我将该线改为Y轴,并使用
xlupper
。非常感谢@xidgel!!