View Single Post
  #4   Report Post  
Posted to microsoft.public.excel.programming
Peter T Peter T is offline
external usenet poster
 
Posts: 5,600
Default ChartAdd event for embedded charts

I don't follow. Apart from the obvious what use is it to you if user clicks
on the plot (I assume you mean to trigger the chart select event). If you
are already trapping the events so what, if you haven't yet trapped the
chart, user clicking or selecting it will not help to tell you if it's a new
chart just added.

In the chart_deactivate you could do say

on error resume next
s = cht.parent.name
on error goto 0
if len(s) = 0 then
the selected chart no longer exist & has just been deleted
Application.Ontime Now, GetCharts ' reset all charts events, if any exist

Regards,
Peter T


"Matt McQueen" wrote in message
...
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