#1   Report Post  
Posted to microsoft.public.excel.charting
external usenet poster
 
Posts: 3
Default Excel 2007 Bug

I have run this code (stripped down code shown below) for over 4 years now
in both Excel 97 and 2003. I am now trying out 2007 but the VBA code to
create my charts is failing. I have found 2 workarounds but it seems like
madness for me to use them. Am I doing something wrong? I think I may be
going mad...



Option Explicit
' Excel 2007 VBA Bug example
'
' Execute BuggedExcel()

Public Sub BuggedExcel()
Dim chtChart As Chart

Dim FixLevel As Integer

FixLevel = 0 'Toggles whether to work-around the Excel 2007 VBA bug.

Set chtChart = ActiveSheet.ChartObjects.Add(0, 0, 184, 95).Chart

Select Case FixLevel
Case 0
'No fix

Case 1
Dim x As Integer
x = chtChart.PlotArea.Top

Case 2
'This fix will only work if you press F5 and not the play button on
the toolbar!
DoEvents

End Select

'The following method (x.Top = 0) fails in Excel 2007 unless the 2 lines
above are executed. Works fine in all previous Excel versions.
'When this fails in 2007, if the User clicks Debug they can step
through/re-run the exact same lines and the code runs without issues.
chtChart.PlotArea.Top = 0

Set chtChart = Nothing

End Sub



  #2   Report Post  
Posted to microsoft.public.excel.charting
external usenet poster
 
Posts: 6,582
Default Excel 2007 Bug

If you do not add data to the chart, either through Chart.SetSourceData,
Chart.SeriesCollection.NewSeries, or Chart.SeriesCollection.Add, there is no
data in the chart, and therefore no chart elements besides the ChartArea.
The fact that

x = chtChart.PlotArea.Top

prevents an error on

chtChart.PlotArea.Top = 0

is, I believe, the error in Excel 2007. If there is no data in the chart,
the "x =" line fails in prior versions of Excel.

What makes Excel 2007 different is that it never creates a chart with
populated data series using ChartObjects.Add, while by default, earlier
versions of Excel will use the current region of the active cell. It is best
always to assign your data explicitly, rather than let Excel to add what it
thinks you want.

- Jon
-------
Jon Peltier, Microsoft Excel MVP
Tutorials and Custom Solutions
http://PeltierTech.com
_______


"WiredUK" wrote in message
...
I have run this code (stripped down code shown below) for over 4 years now
in both Excel 97 and 2003. I am now trying out 2007 but the VBA code to
create my charts is failing. I have found 2 workarounds but it seems like
madness for me to use them. Am I doing something wrong? I think I may be
going mad...



Option Explicit
' Excel 2007 VBA Bug example
'
' Execute BuggedExcel()

Public Sub BuggedExcel()
Dim chtChart As Chart

Dim FixLevel As Integer

FixLevel = 0 'Toggles whether to work-around the Excel 2007 VBA bug.

Set chtChart = ActiveSheet.ChartObjects.Add(0, 0, 184, 95).Chart

Select Case FixLevel
Case 0
'No fix

Case 1
Dim x As Integer
x = chtChart.PlotArea.Top

Case 2
'This fix will only work if you press F5 and not the play button on
the toolbar!
DoEvents

End Select

'The following method (x.Top = 0) fails in Excel 2007 unless the 2
lines above are executed. Works fine in all previous Excel versions.
'When this fails in 2007, if the User clicks Debug they can step
through/re-run the exact same lines and the code runs without issues.
chtChart.PlotArea.Top = 0

Set chtChart = Nothing

End Sub





  #3   Report Post  
Posted to microsoft.public.excel.charting
external usenet poster
 
Posts: 3
Default Excel 2007 Bug

Jon,

Perhaps I should have explained a bit more, but the code I posted was
stripped down completely. The original code does actually add the data, it
goes something like this:

Call chtChart.SeriesCollection.Add(rngSource)

I just took my code and stripped every line out that did not have an effect
on the end result causing the error.

Thanks,
David

"Jon Peltier" wrote in message
...
If you do not add data to the chart, either through Chart.SetSourceData,
Chart.SeriesCollection.NewSeries, or Chart.SeriesCollection.Add, there is
no data in the chart, and therefore no chart elements besides the
ChartArea. The fact that

x = chtChart.PlotArea.Top

prevents an error on

chtChart.PlotArea.Top = 0

is, I believe, the error in Excel 2007. If there is no data in the chart,
the "x =" line fails in prior versions of Excel.

What makes Excel 2007 different is that it never creates a chart with
populated data series using ChartObjects.Add, while by default, earlier
versions of Excel will use the current region of the active cell. It is
best always to assign your data explicitly, rather than let Excel to add
what it thinks you want.

- Jon
-------
Jon Peltier, Microsoft Excel MVP
Tutorials and Custom Solutions
http://PeltierTech.com
_______


"WiredUK" wrote in message
...
I have run this code (stripped down code shown below) for over 4 years now
in both Excel 97 and 2003. I am now trying out 2007 but the VBA code to
create my charts is failing. I have found 2 workarounds but it seems like
madness for me to use them. Am I doing something wrong? I think I may be
going mad...



Option Explicit
' Excel 2007 VBA Bug example
'
' Execute BuggedExcel()

Public Sub BuggedExcel()
Dim chtChart As Chart

Dim FixLevel As Integer

FixLevel = 0 'Toggles whether to work-around the Excel 2007 VBA bug.

Set chtChart = ActiveSheet.ChartObjects.Add(0, 0, 184, 95).Chart

Select Case FixLevel
Case 0
'No fix

Case 1
Dim x As Integer
x = chtChart.PlotArea.Top

Case 2
'This fix will only work if you press F5 and not the play button
on the toolbar!
DoEvents

End Select

'The following method (x.Top = 0) fails in Excel 2007 unless the 2
lines above are executed. Works fine in all previous Excel versions.
'When this fails in 2007, if the User clicks Debug they can step
through/re-run the exact same lines and the code runs without issues.
chtChart.PlotArea.Top = 0

Set chtChart = Nothing

End Sub







  #4   Report Post  
Posted to microsoft.public.excel.charting
external usenet poster
 
Posts: 6,582
Default Excel 2007 Bug

Funny, now it fails for me even if the chart is populated with data.

I can look it over and perhaps submit it as a bug.

- Jon
-------
Jon Peltier, Microsoft Excel MVP
Tutorials and Custom Solutions
http://PeltierTech.com
_______


"WiredUK" wrote in message
...
Jon,

Perhaps I should have explained a bit more, but the code I posted was
stripped down completely. The original code does actually add the data, it
goes something like this:

Call chtChart.SeriesCollection.Add(rngSource)

I just took my code and stripped every line out that did not have an
effect on the end result causing the error.

Thanks,
David

"Jon Peltier" wrote in message
...
If you do not add data to the chart, either through Chart.SetSourceData,
Chart.SeriesCollection.NewSeries, or Chart.SeriesCollection.Add, there is
no data in the chart, and therefore no chart elements besides the
ChartArea. The fact that

x = chtChart.PlotArea.Top

prevents an error on

chtChart.PlotArea.Top = 0

is, I believe, the error in Excel 2007. If there is no data in the chart,
the "x =" line fails in prior versions of Excel.

What makes Excel 2007 different is that it never creates a chart with
populated data series using ChartObjects.Add, while by default, earlier
versions of Excel will use the current region of the active cell. It is
best always to assign your data explicitly, rather than let Excel to add
what it thinks you want.

- Jon
-------
Jon Peltier, Microsoft Excel MVP
Tutorials and Custom Solutions
http://PeltierTech.com
_______


"WiredUK" wrote in message
...
I have run this code (stripped down code shown below) for over 4 years
now in both Excel 97 and 2003. I am now trying out 2007 but the VBA code
to create my charts is failing. I have found 2 workarounds but it seems
like madness for me to use them. Am I doing something wrong? I think I
may be going mad...



Option Explicit
' Excel 2007 VBA Bug example
'
' Execute BuggedExcel()

Public Sub BuggedExcel()
Dim chtChart As Chart

Dim FixLevel As Integer

FixLevel = 0 'Toggles whether to work-around the Excel 2007 VBA bug.

Set chtChart = ActiveSheet.ChartObjects.Add(0, 0, 184, 95).Chart

Select Case FixLevel
Case 0
'No fix

Case 1
Dim x As Integer
x = chtChart.PlotArea.Top

Case 2
'This fix will only work if you press F5 and not the play button
on the toolbar!
DoEvents

End Select

'The following method (x.Top = 0) fails in Excel 2007 unless the 2
lines above are executed. Works fine in all previous Excel versions.
'When this fails in 2007, if the User clicks Debug they can step
through/re-run the exact same lines and the code runs without issues.
chtChart.PlotArea.Top = 0

Set chtChart = Nothing

End Sub









Reply
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
Problems with my links to an excel 2007 file from a word 2007 file sc Links and Linking in Excel 0 February 21st 07 10:12 AM
Excel 2007 Tufail Excel Discussion (Misc queries) 3 February 12th 07 02:22 AM
excel 2007 sammy Excel Discussion (Misc queries) 1 January 25th 07 12:53 AM
Excel 2007 Janunson Excel Worksheet Functions 1 November 7th 06 06:01 PM
Office 2007 Pro Plus 2007 (Beta) - getting small red and green arr Bdhooper1 Excel Discussion (Misc queries) 1 July 19th 06 11:39 PM


All times are GMT +1. The time now is 01:35 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"