CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2
  1. #1
    Join Date
    Jun 1999
    Posts
    9

    Is this possible?

    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


  2. #2
    Join Date
    Jul 1999
    Posts
    20

    Re: Is this possible?

    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


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured