导出/导入代码后图表不会刷新

时间:2019-02-25 13:53:15

标签: excel

使用这些代码,图表显示不会出现问题:

Sub graphit()

  On Error Resume Next
  Set CurrentChart = ActiveSheet.ChartObjects("spectralcht")
  On Error GoTo 0
  If IsEmpty(CurrentChart) Then
       ' init chart if first run
       Set speccht = ActiveSheet.ChartObjects.Add(Left:=100, Width:=500, Top:=100, Height:=300)
       chtcount = ActiveSheet.ChartObjects.Count
       Set speccht = ActiveSheet.ChartObjects(chtcount)
       speccht.Name = "spectralcht"
       With speccht.Chart
         .ChartType = xlXYScatterLinesNoMarkers 'Ensure chart has a title
         .HasTitle = True
         .ChartTitle.Text = "Spectrum (power vs Wavelength)"
         .Legend.Delete
         .Axes(xlValue).MinimumScale = 0
         .Axes(xlValue).MaximumScale = 4000
         .Axes(xlCategory, xlPrimary).HasTitle = True
         .Axes(xlCategory, xlPrimary).AxisTitle.Characters.Text = "WaveLength (nm)"
         .Axes(xlValue, xlPrimary).HasTitle = True
         .Axes(xlValue, xlPrimary).AxisTitle.Characters.Text = "Intencity"
         .Axes(xlCategory, xlPrimary).HasMajorGridlines = True
         .Axes(xlCategory, xlPrimary).HasMinorGridlines = True
         .Axes(xlCategory, xlPrimary).MajorGridlines.Border.Color = RGB(0, 0, 255)
         .Axes(xlCategory, xlPrimary).MajorGridlines.Border.LineStyle = xlDash
      End With
  End If

  'chage axe for new WL
  Set speccht = ActiveSheet.ChartObjects("spectralcht")
  With speccht.Chart
         .Axes(xlCategory).MinimumScale = CDbl(MinWL.Value)
         .Axes(xlCategory).MaximumScale = CDbl(MaxWL.Value)
  End With

  ' plot graph
  With speccht.Chart.SeriesCollection
      If .Count = 0 Then .NewSeries
      .Item(1).Values = Spectrum()
      .Item(1).XValues = Wavelengths()
  End With

End Sub

但是,如果我将表单导出到另一本书上,则不会显示数据! 它显示图表,轴,但没有数据也没有图表。 我现在有点迷路了 事先怜悯 拍拍

0 个答案:

没有答案