Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/excel/24.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
Excel 对象没有';不支持属性或方法';。数据标签';_Excel_Vba - Fatal编程技术网

Excel 对象没有';不支持属性或方法';。数据标签';

Excel 对象没有';不支持属性或方法';。数据标签';,excel,vba,Excel,Vba,有人能告诉我是什么产生了“对象不支持属性或方法”错误消息吗?通过调试器查看,似乎不支持“.Datalabels”。是因为我指定的是对象而不是图表吗 第一个子例程应该确定我选择了一个图表还是多个图表。第二个子例程假定将我的格式应用于图表 Sub DetermineSelection() 'Determines what to process (active chat or selected chart) Dim obj As Object If Not ActiveChart I

有人能告诉我是什么产生了“对象不支持属性或方法”错误消息吗?通过调试器查看,似乎不支持“.Datalabels”。是因为我指定的是对象而不是图表吗

第一个子例程应该确定我选择了一个图表还是多个图表。第二个子例程假定将我的格式应用于图表

Sub DetermineSelection()
'Determines what to process (active chat or selected chart)
    Dim obj As Object

    If Not ActiveChart Is Nothing Then
        FormatNASATLXChart ActiveChart
    Else
        For Each obj In Selection
            If TypeName(obj) = "ChartObject" Then
                FormatNASATLXChart obj.Chart
            End If
        Next
    End If
End Sub
Sub FormatNASATLXChart(cht As Chart)
'Format chart with NASA TLX Label (i.e. Mental Workload)
    With cht.SeriesCollection(1)
        .DataLabels = True
        .ShowSeriesName = True
        .ShowValue = False
        .Position = xlLabelPositionInsideBase
    End With

    With cht.SeriesCollection(2)
        .HasDataLabels = True
        .ShowSeriesName = True
        .ShowValue = False
        .Position = xlLabelPositionInsideBase
    End With

    With cht.SeriesCollection(3)
        .HasDataLabels = True
        .ShowSeriesName = True
        .ShowValue = False
        .Position = xlLabelPositionInsideBase
    End With

    With cht.SeriesCollection(4)
        .HasDataLabels = True
        .ShowSeriesName = True
        .ShowValue = False
        .Position = xlLabelPositionInsideBase
    End With

    With cht.SeriesCollection(5)
        .HasDataLabels = True
        .ShowSeriesName = True
        .ShowValue = False
        .Position = xlLabelPositionInsideBase
    End With
End Sub
第二个子例程假定将我的格式应用于图表

Sub DetermineSelection()
'Determines what to process (active chat or selected chart)
    Dim obj As Object

    If Not ActiveChart Is Nothing Then
        FormatNASATLXChart ActiveChart
    Else
        For Each obj In Selection
            If TypeName(obj) = "ChartObject" Then
                FormatNASATLXChart obj.Chart
            End If
        Next
    End If
End Sub
Sub FormatNASATLXChart(cht As Chart)
'Format chart with NASA TLX Label (i.e. Mental Workload)
    With cht.SeriesCollection(1)
        .DataLabels = True
        .ShowSeriesName = True
        .ShowValue = False
        .Position = xlLabelPositionInsideBase
    End With

    With cht.SeriesCollection(2)
        .HasDataLabels = True
        .ShowSeriesName = True
        .ShowValue = False
        .Position = xlLabelPositionInsideBase
    End With

    With cht.SeriesCollection(3)
        .HasDataLabels = True
        .ShowSeriesName = True
        .ShowValue = False
        .Position = xlLabelPositionInsideBase
    End With

    With cht.SeriesCollection(4)
        .HasDataLabels = True
        .ShowSeriesName = True
        .ShowValue = False
        .Position = xlLabelPositionInsideBase
    End With

    With cht.SeriesCollection(5)
        .HasDataLabels = True
        .ShowSeriesName = True
        .ShowValue = False
        .Position = xlLabelPositionInsideBase
    End With
End Sub
更改您的以下行:

.DataLabels = True
致:

在cht.SeriesCollection(1)


您可以用
For
循环替换代码,该代码将完全相同的命令重复5次

Dim i As Long

For i = 1 To 5
    With cht.SeriesCollection(i)
        .HasDataLabels = True
        .ShowSeriesName = True
        .ShowValue = False
        .Position = xlLabelPositionInsideBase
    End With
Next i

我想是这样的,但我没有看到任何参考资料表明“.DataLabels”有任何问题。现在,我收到了与“.ShowSeriesName”相同的错误消息。但根据这一有效语法。