Molle
October 26th, 1999, 05:48 AM
Hiya!
I'm wondering if its possible to export data from vb5 to an excel sheet and use that data as a range for a chart? I have the excel sheet with the chart and have exported the data but I can't set the range for the chart from vb. Is it possible if so how?
Thanks.
Magnus
Praba S
October 26th, 1999, 09:13 PM
Hi
It is possible
Check the following code.
Create a new project .
Add a command button in form1.
Copy the following code in the form module.
Click the button
***Code starts here
Private Sub Command1_Click()
Dim xlApp As Excel.Application
Dim xlBook As Excel.Workbook
Dim xlSheet As Excel.WorkSheet
Set xlApp = CreateObject("Excel.Application")
Set xlBook = xlApp.Workbooks.Add
Set xlSheet = xlBook.Worksheets(1)
xlSheet.Range("a1") = "Month"
xlSheet.Range("b1") = "Sales Value"
xlSheet.Range("a2") = "Jan"
xlSheet.Range("a3") = "Feb"
xlSheet.Range("a4") = "Mar"
xlSheet.Range("b2") = "50"
xlSheet.Range("b3") = "200"
xlSheet.Range("b4") = "10"
With xlBook
.Charts.Add
.ActiveChart.ChartType = xlColumnClustered
.ActiveChart.SetSourceData Source:=Sheets("Sheet1").Range("a1:b4"), PlotBy:= _
xlColumns
.ActiveChart.Location Where:=xlLocationAsObject, Name:="Sheet1"
With ActiveChart
.HasTitle = True
.ChartTitle.Characters.Text = "sales new"
.Axes(xlCategory, xlPrimary).HasTitle = False
.Axes(xlValue, xlPrimary).HasTitle = False
End With
End With
xlApp.Visible = True
End Sub
** Code end s here
rgds
Praba