I actually record the excel marco as I insert the chart and format it. Then taking the VBA code from there.
Now I need to create a chart in excel using VB 2005 so I was wondering if anyone could guide me on converting the code?
here's the VBA 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
With Selection.Border
.ColorIndex = 57
.Weight = xlMedium
.LineStyle = xlContinuous
End With
End Sub
So far I have already done the opening of excel file and putting in Excel namespace:
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
When I tried running, the axis in opposite to what I want.
I tried ways to correct it and inserting more code (refering to VBA code) but errors occurs, like xlLines , xlColumns are not declared...etc.
I dunno how to proceed on.
HELP..guidance??!!
This post has been edited by bellaelysium: 16 June 2008 - 10:05 PM


Reply





MultiQuote







|