I need to use
VB 2005 studio to create chart in Excel.
I actually record the Excel macro while inserting chart and all.
And now I have the VBA code.
However, I tried inserting into my
VB 2005 and modify,
but I have some errors.
here's the VBA code:
================================================== ==
Code:
Charts.Add
ActiveChart.ChartType = xlLine
ActiveChart.SetSourceData Source:=Sheets("Copy of
trial").Range("A1:H23"), _
PlotBy:=xlColumns
ActiveChart.Location Where:=xlLocationAsNewSheet
With ActiveChart
.HasTitle = True
.ChartTitle.Characters.Text = "Animal Rack Monitor"
.Axes(xlCategory, xlPrimary).HasTitle = True
.Axes(xlCategory, xlPrimary).AxisTitle.Characters.Text =
"Time/Date"
.Axes(xlValue, xlPrimary).HasTitle = True
.Axes(xlValue, xlPrimary).AxisTitle.Characters.Text =
"Measurements"
End With
With ActiveChart.Axes(xlCategory)
.HasMajorGridlines = True
.HasMinorGridlines = True
End With
With ActiveChart.Axes(xlValue)
.HasMajorGridlines = True
.HasMinorGridlines = True
End With
ActiveChart.HasLegend = True
ActiveChart.Legend.Select
Selection.Position = xlRight
ActiveChart.SeriesCollection(1).Select
With Selection.Border
.ColorIndex = 57
.Weight = xlMedium
.LineStyle = xlContinuous
End With
With Selection
.MarkerBackgroundColorIndex = xlNone
.MarkerForegroundColorIndex = xlNone
.MarkerStyle = xlNone
.Smooth = False
.MarkerSize = 3
.Shadow = False
End With
ActiveChart.SeriesCollection(1).AxisGroup = 2
ActiveChart.SeriesCollection(4).Select
End Sub
================================================== ==
and the code i did in
VB 2005 which is working ok:
=================================================
Code:
Dim objExcelC As Excel.Chart
WExcel.Charts.Add()
objExcelC = WBook.ActiveChart
objExcelC.Activate()
objExcelC.ChartType = Excel.XlChartType _
.xlLineMarkers
objExcelC.SetSourceData(Source:=range)
objExcelC.Name = "ARM Chart"
objExcelC.HasTitle = True
'objExcelC.ChartTitle.Text = _
"Animal Rack Monitor"
End Sub
End Class
================================================== ======
So can anyone guide me?
Some errors occurs when I attempt to convert are like xlLines, xlColumns are not declared....etc.
HELP??!!