Charts in Excel 2007

Vishesh's picture

Just Check the attached sheet and run it in Excel 2003, 2007 & 2010 beta. Double clicking on any of the charts in 2007 will crash Excel. Uncomment the lines commented in the sheet code and you will find that it runs fine in Excel 2007 too.

AttachmentSize
ChartEvents.xls30.5 KB
Nick's picture

Excel crashing

hi hivishy

I suspect that an event may be triggered whilst another event is being actioned.

I suggest the following:

At each entry point to an event, put: Application.enableevents = false

At each exit point, put: Application.enableevents = true

 

Nick

 

Vishesh's picture

Charts in Excel 2003, 2007 and 2010 beta

 

No. This didn't work.

Just have a look at the following code. This code works fine in Excel 2003 and 2010 beta version but crashes in 2007. To avoid this you need to uncomment the lines in the following code (in bold below). Based on this I reached the conclusion that at the end of the chart event if you try to activate/select anything other than the chart it will crash in Excel 2007.


Public WithEvents Cht1 As Chart

Public WithEvents Cht2 As Chart

 

Public Sub InitCharts()

    Set Cht1 = shtChart.ChartObjects(1).Chart

    Set Cht2 = shtChart.ChartObjects(2).Chart

End Sub

 

Private Sub cht1_BeforeDoubleClick(ByVal ElementID As Long, ByVal Arg1 As Long, ByVal Arg2 As Long, Cancel As Boolean)

    Cancel = True

    shtChart.Range("A1").Select

    'Cht2.Parent.Select 'Uncomment this in 2007

End Sub

 

Private Sub Cht2_BeforeDoubleClick(ByVal ElementID As Long, ByVal Arg1 As Long, ByVal Arg2 As Long, Cancel As Boolean)

    Cancel = True

    shtChart.Range("A1").Select

    'Cht1.Parent.Select 'Uncomment this in 2007

End Sub

 

Private Sub Worksheet_Activate()

    Call shtChart.InitCharts

End Sub

 

Nick's picture

Chart problem

hey.. can you add an example file pls, and I'll take a look.

Vishesh's picture

Chart Problem

Example file attached.

Nick's picture

Chart problem - crashing Excel

crashes for me too..

Do you actually need to select the worksheet though ?

Nick

 

Vishesh's picture

Chart problem - crashing Excel

Did u try uncommenting the commented lines ? Did u try running this example sheet in Excel 2003 or Excel 2010 beta version ?

There are four charts visible at a time on the sheet. Double clicking on any of the charts will filter (using filters) the data for it (data on another sheet) and show its data and hide the chart. Same with other charts as well.

But another thing that I observed with filters (VBA) is that when you execute filters the focus actually shift to the sheet on which the filter is being applied.

Dont you find this interesting ?

Vishesh's picture

Chart Problem

Just paste the code in the Sheet module. In the same sheet create 2 charts based on any data and try clicking on the charts. This would raise those events that I talked about in my post. In my post sheet name is shtChart.