ChartAdd event for embedded charts
Peter,
I catch your drift - however if the user doesn't click on the plot s/he just
created then I'd be left with the same problem.
I'll mess around a bit more and see if I can get the chart_deactivate to work.
Cheers,
Matt
"Peter T" wrote:
As you say no events are triggered when creating or deleting a chartobject
(though an event is triggered when a chart-sheet is activated or added). So
it means using whatever other events are available, eg sheet activate or
workbook activate
Try the following in ThisWorkbook module, a normal module and a class module
as indicated
' thisworkbook module
Private Sub Workbook_SheetActivate(ByVal Sh As Object)
GetCharts Sh
End Sub
Private Sub Workbook_SheetDeactivate(ByVal Sh As Object)
Set gCol = Nothing
End Sub
'' add similar event for workbook actrivate/deactivate
'''' in a normal module
Public gCol As Collection
Sub GetCharts(sht As Object)
Dim i As Long
Dim chtObj As ChartObject
Dim c As Class1
' code here to disable your button, or perhaps after
' If not gCol is nothing then.. etc
For i = 1 To sht.ChartObjects.Count
If i = 1 Then
Set gCol = New Collection
' code here to enable your button
End If
Set c = New Class1
Set c.cht = sht.ChartObjects(i).Chart
gCol.Add c, c.cht.Name
Next
End Sub
'' code in Class1
Public WithEvents cht As Chart
' select cht events from the top mid dropdawn then
' chart events from the top rt dropdown
Private Sub cht_MouseDown(ByVal Button As Long, ByVal Shift As Long, _
ByVal x As Long, ByVal y As Long)
MsgBox cht.Name
End Sub
Regards,
Peter T
|