CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2
  1. #1
    Join Date
    Aug 1999
    Location
    Québec (Canada)
    Posts
    210

    Object Microsoft Excel Chart

    I put object Microsoft Excel Chart in my form and the chart was build with sheet1 situate in the object Chart1 but I will like to change data on sheet1 to make a new chart but I not able.

    I try with Worksheet("Sheet1").cells(2, 3).value = new value but I receive all the time this error "Method or data member not found" for Worksheets.

    My problem is "am not able to select the sheet in the object(Chart1)"

    I will like to take data in DBGrid and put them in Sheet1 to make new chart.

    Help me !

    Sorry for my english
    Thanks
    Redg



  2. #2
    Join Date
    Feb 2000
    Posts
    12

    Re: Object Microsoft Excel Chart

    try this

    Dim xlApp As Excel.Application
    Dim xlWrkbk As Excel.Workbook
    Dim xlChartObj As Excel.Chart
    Dim xlSourceRange As Excel.Range
    Dim xlColPoint As Excel.Point

    Set xlApp = CreateObject("Excel.Application")
    Set xlWrkbk = xlApp.Workbooks.Open("c:\1.xls")

    Set xlSourceRange = xlWrkbk.Worksheets(1).Range("a:b").CurrentRegion

    Set xlChartObj = xlApp.Charts.Add

    With xlChartObj ' Specify chart type as 3D.
    .ChartType = xlLine
    ' Set the range of the chart.

    .SetSourceData Source:=xlSourceRange, PlotBy:=xlColumns

    ' Specify that the chart is located on a new sheet.
    .Location Where:=xlLocationAsNewSheet
    ' Create and set the title; set title font.
    .HasTitle = True
    With .ChartTitle
    .Characters.Text = "My Title"
    .Font.Size = 18
    End With
    ' Rotate the x-axis labels to a 45-degree angle.

    .Axes(xlCategory).TickLabels.Orientation = 45

    ' Delete the label at the far right of the x-axis.

    .HasLegend = False

    End With
    With xlWrkbk
    .Save

    .Close
    End With

    xlApp.Quit

    Set xlApp = Nothing
    Set xlWrkbk = Nothing
    Set xlChartObj = Nothing

    End Sub


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