我有一个宏,可以在气泡图中添加数据标签。此代码提供Y轴的值。
我想改为显示SeriesName。
Sub AddDataLabels()
Dim bubbleChart As ChartObject
Dim mySrs As Series
Dim myPts As Points
With ActiveSheet
For Each bubbleChart In .ChartObjects
For Each mySrs In bubbleChart.Chart.SeriesCollection
Set myPts = mySrs.Points
myPts(myPts.Count).ApplyDataLabels Type:=xlShowValue
Next
Next
End With
End Sub
我尝试过更改
myPts(myPts.Count).ApplyDataLabels Type:=xlShowValue
分为:
myPts(myPts.Count).ApplyDataLabels Type:=xlShowSeriesName
它给了我
'无效的程序调用或参数'
如何更改代码以显示SeriesName而不是Y轴值?
截图
答案 0 :(得分:0)
这对你有用吗?
bubbleChart.ApplyDataLabels xlDataLabelsShowLabel
答案 1 :(得分:0)
在我的代码中添加With
语句在您的代码中,并根据您的需要调整内部参数。
在下面的代码中,图表Daralabels
会显示SeriesName
,但不显示类别或值。
Sub AddDataLabels()
Dim bubbleChart As ChartObject
Dim mySrs As Series
Dim myPts As Points
With ActiveSheet
For Each bubbleChart In .ChartObjects
For Each mySrs In bubbleChart.Chart.SeriesCollection
Set myPts = mySrs.Points
myPts(myPts.Count).ApplyDataLabels
With myPts(myPts.Count).DataLabel
.ShowSeriesName = True
.ShowCategoryName = False
.ShowValue = False
' optional parameters
.Orientation = 0
.Font.Size = 10
.Font.Bold = True
End With
Next
Next
End With
End Sub