提出问题提出问题
 

问题Chartobjects is behaving oddly

  • 2009年7月8日 21:10Kdayton 用户奖牌用户奖牌用户奖牌用户奖牌用户奖牌
     
    VBA  (6.3) for excel2003

    Here is the basic pieces of the code (I'm retyping this so if you notice typos that's not the issue):

    set MyChart = wrksheet.chartObjects.Add(left:=100, width:=100, top:=100, height:=100)

    with MyChart
      .Name = "ABC"
      .Chart.ChartType = xlColumnClustered
      .Chart.seriesCollection.NewSeries
      .Chart.seriesCollection.NewSeries
      .Chart.seriesCollection(1).Name = wrksheet.cells(1,"A").value**
      .Chart.seriesCollection(1).Value = wrksheet.range("A2:A10")
      .Chart.seriesCollection(2).Name = wrksheet.cells(1,"B").value**
      .Chart.seriesCollection(1).Value = wrksheet.range("B2:B10")
    end with

    ...

    wrksheet.ChartObects("ABC").left = wrksheet.Cells(3,"A").Left**

    ------

    The lines with the ** are my issues

    The code works if I step into it (F8) but if I run the macro it behaves in an unexpected manner.  For example the line to name the Collection does not name it.  If the name is suppose to be "Fred" it just leaves it as "Series 1".  Also, the line that moves it to a particular cell (chartObject.LEFT) does not do it, and the chart stays in the location that it was created. 

    Again, if I step line by line through it (even if I hold F8 down) the charts Collections are named properly and the chart is moved to correct location.  It is only when the macro is run that these lines seem to be avoided or stepped past.  It's almost as if the computer can not perform the request because it's moving to fast...I'm just guessing, because I don't know what it's really doing.

    Is there someone that's seen this behavior, I have 14 charts to draw on about 40 sheets and holding down F8 as a fix is just not going to cut it.

    Thank you in advance.
    ------

全部回复

  • 2009年7月9日 2:23ShasurMVP用户奖牌用户奖牌用户奖牌用户奖牌用户奖牌
     
    Why can't you try doing it this way

    set MyChart = wrksheet.chartObjects.Add(left:=wrksheet.Cells(3,"A").Left, width:=100, top:=100, height:=100)

    Cheers
    Shasur
    http://www.vbadud.blogspot.com
  • 2009年7月10日 20:51Kdayton 用户奖牌用户奖牌用户奖牌用户奖牌用户奖牌
     
    I didn't try it because I didn't know that that was legal.  I will definitely try that.   Thank you.