Chart Event (Double Click on Chart)
The example file attached shows how to create events for charts. Here, I have created double click event for charts. The chart which is double-clicked is exported to PowerPoint. Download the example file and have a look for yourself. See the code in Thisworkbook and mod_PPT module.
Attachment | Size |
---|---|
ChartEvents.xls | 47 KB |
»
- Vishesh's blog
- Login or register to post comments
- 25784 reads
What if the chart is created after the workbook is open?
Hello and thanx for your post. It helped me alot.
But how do I do it if I create the chart after the workbook is opened?
In your example you set Cht1 = Sheet1Chart.... .Chart in the Workbook_Open Sub.
How do i do it in a module sub?
'Code to create chart
'Code to attach this chart to a event?
Refer to this
Refer to this url
http://excelexperts.com/Classes-Single-event-for-multiple-labels
You need to uses classes.
Or, run a code that assigns the macro to a chart/shape.
I did like this and it
I did like this and it assigns the proper Macro to the shape on the chart.
But what do I need to do with the chart/shape to activate it?
Sub addtmpchart()
Dim GCShape As shape
Dim GCChart As Chart
Dim name As String
ActiveSheet.Shapes.AddChart.Select
Set GCChart = ActiveSheet.ChartObjects(1).Chart
name = GCChart.name
name = Right(name, 7)
Set GCShape = ActiveSheet.Shapes(name)
GCShape.OnAction = "'" & ActiveWorkbook.name & "'!popMsgBox"
End Sub
Sub popMsgBox()
MsgBos "YEEAAH"
End Sub
If you write the correct name
If you write the correct name of the macro, just click the chart. :)
I tried to assign a macro to
I tried to assign a macro to the chart but cant find out how to do it.
For a shape you can write:
Dim MyShape As Shape
Set MyShape = ActiveSheet.Shapes.AddShape(msoShapeRectangle, 10, 10, 10, 10)
MyShape.Onaction = "'" & activeworkbook.name & "'!macro_name"
But the Chart object does not have the function named "OnAction". How do i do it?
Or can I refer to a shape inside the Chart somehow? (Dont now if charts consists of shapes)
Or do I need to use classes?
Thank you.