在excel中录制了一段绘制折线图的代码,在vb中调用,老是出问题,谁那里有段vb调用excel绘制折线图的程序呀,参考一下,谢谢。

解决方案 »

  1.   

     dim oExcel 
      Set oExcel = CreateObject("Excel.Application")
      oExcel.Visible = True 
      oExcel.Workbooks.Add 
      oExcel.Workbooks(1).Worksheets("sheet1").Activate 
       For i =1 To NumberOfTimeInstants
          redim solution(1)
          solution(0)=1
          solution(1)=TimeInstants(i-1) 
          Set Field = Sol.getTransientField(solution, "|B| smoothed")      
          CALL Field.getFieldAtPoint (x, y, z, value)
          Bvalue(i-1)=value(0)
          oExcel.Cells(i, 1).Value = TimeInstants(i-1)
          oExcel.Cells(i, 2).Value = Bvalue(i-1)
       Next 
        
       oExcel. Charts.Add 
       oExcel. ActiveChart.ChartType =xlLine 
        oExcel.ActiveChart.SetSourceData Source:=Sheets("Sheet1").Range("A1:B201"), PlotBy _ 
            :=xlColumns 
        ActiveChart.SeriesCollection(2).Delete 
        ActiveChart.SeriesCollection(1).XValues = "=Sheet1!R1C1:R201C1" 
        ActiveChart.SeriesCollection(1).Values = "=Sheet1!R1C2:R201C2" 
        ActiveChart.Location Where:=xlLocationAsObject, Name:="Sheet1" 
        With ActiveChart 
            .HasTitle = True 
            .ChartTitle.Characters.Text = "|B|随时间变化" 
            .Axes(xlCategory, xlPrimary).HasTitle = True 
            .Axes(xlCategory, xlPrimary).AxisTitle.Characters.Text = "t(ms)" 
            .Axes(xlValue, xlPrimary).HasTitle = True 
            .Axes(xlValue, xlPrimary).AxisTitle.Characters.Text = "|B|(T)" 
        End With 
        ActiveWindow.Visible = False 
        Windows("Bvalue.xls").Activate