Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Very wierd problem. Please help

I wrote a piece of code to generate a bunch of charts(40) in a
worksheet. It was running smoothly and generate some beautiful charts.
However, last Thursday it stops due to a run-time error while running,
23 charts has been generated. The error message is "Unable to set the
HasTitle property of the Axis class". It is very wierd because the
code is in a loop and it pass the first 23 charts and block the 24th.

Then I tried some modification and thought the problem maybe related
to the font limitation in a chart. (see http://support.microsoft.com/kb/215573)
this DOESN'T work.

Then I try to run this code twice and triple. Find it is interesting
that at first, it stops at 24th. If you stop and re-run, it stops at
17th and give another error message, similar to "unable to set xxx
property of xxx class". If you stop and re-run for third time. It just
go through!!! What a damn!!! If you re-run for forth time, it stops at
24th again. then repeat.


Please help me, save me!


Following is the code.

Set cht1 = wsChart.ChartObjects.Add(posLeft, posTop, posWidth,
posHeight)

With cht1.Chart
.ChartType = xlLine

.SeriesCollection.NewSeries
.SeriesCollection(1).Name = "Projected Net Loss"
.SeriesCollection(1).Border.ColorIndex = 25
.SeriesCollection(1).Border.Weight = xlMedium
.SeriesCollection(1).Border.LineStyle = xlContinuous
.SeriesCollection(1).XValues = rngMonth
.SeriesCollection(1).Values = rngProLoss

.SeriesCollection.NewSeries
.SeriesCollection(2).Name = "Actual Net Loss"
.SeriesCollection(2).Border.ColorIndex = 3
.SeriesCollection(2).Border.Weight = xlThick
.SeriesCollection(2).Border.LineStyle = xlContinuous
.SeriesCollection(2).XValues = rngMonth
.SeriesCollection(2).Values = rngActLoss

.SeriesCollection.NewSeries
.SeriesCollection(3).Name = "PCG Projected Net Loss"
.SeriesCollection(3).Border.ColorIndex = 33
.SeriesCollection(3).Border.Weight = xlMedium
.SeriesCollection(3).Border.LineStyle = xlContinuous
.SeriesCollection(3).XValues = rngMonth
.SeriesCollection(3).Values = rngPCGProLoss

.Legend.Position = xlLegendPositionBottom

.HasTitle = True
.ChartTitle.Characters.Text = rngTitle.Value & " " &
rngTitle.Offset(0, 2).Value
.ChartTitle.Characters.Font.Size = 10
.ChartTitle.Font.Bold = True
.ChartTitle.Left = 35

.Axes(xlCategory, xlPrimary).HasTitle = True '<- Get error message
here.
.Axes(xlCategory, xlPrimary).AxisTitle.Characters.Text = "Month"
.Axes(xlCategory, xlPrimary).AxisTitle.Font.Size = 9
.Axes(xlCategory, xlPrimary).CrossesAt = 1
.Axes(xlCategory, xlPrimary).TickLabelSpacing = 6
.Axes(xlCategory, xlPrimary).TickMarkSpacing = 6
.Axes(xlCategory, xlPrimary).TickLabels.Orientation = 90
.Axes(xlCategory, xlPrimary).TickLabels.Font.Size = 9
.Axes(xlValue, xlPrimary).HasTitle = True
.Axes(xlValue, xlPrimary).AxisTitle.Characters.Text = "Loss
$1000s"
.Axes(xlValue, xlPrimary).AxisTitle.Font.Size = 9
.Axes(xlValue, xlPrimary).MinimumScale = 0
.Axes(xlValue, xlPrimary).TickLabels.Font.Size = 9

.Legend.Border.LineStyle = xlNone
.Legend.Font.Size = 9

'.PlotArea.Border.LineStyle = xlNone
.PlotArea.Interior.ColorIndex = xlNone
.Axes(xlValue, xlPrimary).MajorGridlines.Border.LineStyle = xlDot

Set cht1 = Nothing

End With

Thank you! any suggestion appreciated.

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 789
Default Very wierd problem. Please help

Hi
I find that anything that involves updating charts can always do with
a sprinkling of DoEvents. So put

DoEvents

in after you do the .HasTitle = True. No harm to put it in after
other .HasTitle lines too.
I think (and it is a wild guess) that the code runs ahead trying to
manipulate the Title object before it is properly created. The
DoEvents forces the object to be properly created before you
manipulate it.
hope it helps!
Paul

On May 15, 4:30 am, Francis wrote:
I wrote a piece of code to generate a bunch of charts(40) in a
worksheet. It was running smoothly and generate some beautiful charts.
However, last Thursday it stops due to a run-time error while running,
23 charts has been generated. The error message is "Unable to set the
HasTitle property of the Axis class". It is very wierd because the
code is in a loop and it pass the first 23 charts and block the 24th.

....

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
Very Wierd Execl "Memory" problem Pat Excel Discussion (Misc queries) 3 October 26th 06 03:39 PM
This is wierd! semiopen Excel Programming 0 September 22nd 06 05:54 PM
Wierd Save problem Gareth Saunders Excel Discussion (Misc queries) 2 May 11th 06 04:32 PM
WIERD Excel Problem BK Setting up and Configuration of Excel 8 April 7th 06 12:17 AM
Wierd variable values problem [email protected] Excel Programming 3 December 5th 05 06:13 PM


All times are GMT +1. The time now is 07:42 AM.

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

About Us

"It's about Microsoft Excel"