Excel 对象没有';不支持属性或方法';。数据标签';
有人能告诉我是什么产生了“对象不支持属性或方法”错误消息吗?通过调试器查看,似乎不支持“.Datalabels”。是因为我指定的是对象而不是图表吗 第一个子例程应该确定我选择了一个图表还是多个图表。第二个子例程假定将我的格式应用于图表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
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”相同的错误消息。但根据这一有效语法。