点击该系列,从图表中获取系列名称

我想通过点击它从特定的图表获取时间序列名称。 我有这样的东西:

Sub CallSerie() CallingShapeName = ActiveSheet.Shapes(Application.Caller).Name MsgBox CallingShapeName End Sub 

但是这会抛出图表名称,而不是系列名称。

你不想为图表分配一个macros – 最好使用它的事件。 下面的代码假设你有一个图表embedded工作表,代码需要进入该工作表的代码模块:

 Private WithEvents cht As Excel.Chart Private Sub cht_MouseUp(ByVal Button As Long, ByVal Shift As Long, ByVal x As Long, ByVal y As Long) Dim IDNum As Long Dim a As Long Dim b As Long cht.GetChartElement x, y, IDNum, a, b If IDNum = xlSeries Then MsgBox cht.SeriesCollection(a).Name End Sub Private Sub Worksheet_Activate() HookChart End Sub Public Sub HookChart() Set cht = Me.ChartObjects(1).Chart End Sub 

然后只需激活一张不同的工作表并切换回工作表(或者运行HookChart例程),然后单击一个图表系列。