首页 > 解决方案 > 导出/导入代码后图表不会刷新

问题描述

使用这些代码图表显示没有问题:

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

但是,如果我将表格导出并导入另一本书,它将不会显示数据!它显示图表,轴,但没有数据没有图表。在这一点上我有点失落谢谢提前拍

标签: excel

解决方案


推荐阅读