LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Class Collection - trapped events keep repeating!

Hi,

I am experimenting with trapping chart events using class modules. I
have a class module 'ChartEvents' that traps the double click event for
charts, and a normal module with the following code:

Option Explicit
Dim clsCharts As New Collection

Public Sub InitialiseChartEvents()
Dim wks As Worksheet
Dim iChart As ChartObject
Dim aChart As ChartEvents

For Each wks In ActiveWorkbook.Worksheets
For Each iChart In wks.ChartObjects
Set aChart = New ChartEvents
Set aChart.aChart = wks.ChartObjects(iChart.Index).Chart
Call clsCharts.Add(aChart)
Debug.Print ThisWorkbook.Name & " - " & wks.Name & " - " &
iChart.Name
Next iChart
Next wks

End Sub

ChartEvents module has following declaration (the event trapping code
is irrelevant i think):
Public WithEvents aChart As Chart



So basically the code loops through each worksheet, and adds every
chart in the workbook to the clsCharts collection, as a member of the
ChartEvents class.

The problem is, I want the user to be able to add a new chart, then
click a button that re-runs this routine again, so that the new chart
is included in the collection. But if I do that, then it seems it adds
a second copy of all the original charts, and so if i double click on
one of these charts, it runs the trapped event code twice.... and if i
run the InitialiseChartEvents code 10 times, it will have added 10
copies, and runs the double click code 10 times!

So first of all: Is there a better way of adding new items to a
collection just once? Or should this be done without using a collection
at all (if so how)?

But secondly, and to be honest more importantly to my understanding of
class modules and collections, can I write the InitialiseChartEvents
code so that it terminates the entire ChartEvents class, or just kills
the clsCharts collection, up front and then re-adds all the charts from
scratch? This seemed to me to be this easiest fix, and I've searched
and searched for how to do this but to no avail. Probably i'm missing
something really dumb.... or maybe its just impossible.

Any help on both points much appreciated.

Stuart

 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Class Collection Add Items keep repeating Kevin Vaughn Excel Programming 3 April 18th 06 10:50 PM
Need Class Collection advice R Avery Excel Programming 3 April 6th 04 10:34 AM
Collection Class problems Flemming Dahl Excel Programming 4 February 11th 04 04:41 PM
RaiseEvent from a class contained in a 2nd class collection? Andrew[_16_] Excel Programming 2 January 6th 04 04:22 PM
For/Each iteration for collection class Stelio Excel Programming 1 October 31st 03 12:46 PM


All times are GMT +1. The time now is 08:59 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"