View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
Peter T Peter T is offline
external usenet poster
 
Posts: 5,600
Default Apparent Excel 2007 chart HasTitle race condition

That's ridiculous isn't it!
Couple more workarounds, though not sure if any better than your pair of
Doevents, which also work for me

Application.ScreenUpdating = True
ch.HasTitle = False

or
' at module level
Private mCht as chart

' code
ch.HasTitle = False
Set mCht = ch
Application.OnTime Now, "noTitle"
End Sub

Sub noTitle()
mCht.HasTitle = False
End Sub

If you've making several charts this would need to be done differently but
basically same idea

or stick with your pair of DoEvents

Regards,
Peter T


"Graham F" wrote in message
...
The macro below works correctly, i.e. creates a chart without a title,
with
Excel 2003, but the chart has a title with Excel 2007 SP2 and the Excel
2010
beta. (The macro requires numeric data in the range A1:B10 on the first
worksheet.)

The macro *does* work correctly with Excel 2007 if I step through it in
the
debugger (thus introducing delays between each statement), or if I
introduce
additional statements before the ch.HasTitle statement (in particular
*two*
DoEvents calls seems to work).

My company's application that uses Excel for reports has larger macros
containing similar code that must run correctly on many PCs. Does anyone
know of a safe fix or work-around for this problem?

Sub Macro1()
Dim ws As Worksheet
Dim ch As Chart
Dim s As Series

' Add chart.
Set ws = Worksheets(1)
Set ch = ws.ChartObjects.Add(100, 100, 400, 400).Chart
ch.ChartType = xlXYScatterLines
' Add series to chart.
Set s = ch.SeriesCollection.NewSeries
s.Name = "My series"
s.Values = ws.Range(ws.Cells(1, 2), Cells(10, 2))
s.XValues = ws.Range(ws.Cells(1, 1), Cells(10, 1))
' No title.
ch.HasTitle = False
End Sub

Graham