aa9gg 0 Newbie Poster

Hi all....
I'm trying to insert an Excel graph into my application. It was pre-made in MS Excel, but I need to update and display the graphed results in my VB6 application. I inserted the graph on my form using OLE and I found this on the web:

'do declare these variables you need to add a reference
'to the microsoft excel 'xx' object library.

'you need two text boxes and two command buttons
'on the form, an excel file in c:\book1.xls

Dim xl As New Excel.Application
Dim xlwbook As Excel.Workbook
Dim xlsheet As Excel.Worksheet

Private Sub Command1_Click()
'the benifit of placing numbers in (row, col) is that you
'can loop through different directions if required. I could
'have used column names like "A1" 'etc.

    Text1(0).Text = xlsheet.Cells(5, 2) ' row 2 col 1
    Text1(1).Text = xlsheet.Cells(5, 3) ' row 2 col 2
    Text1(2).Text = xlsheet.Cells(5, 4) ' row 2 col 2
    Text1(3).Text = xlsheet.Cells(5, 5) ' row 2 col 2

End Sub

Private Sub Command2_Click()
    xlsheet.Cells(5, 2) = Text1(0).Text
    xlsheet.Cells(5, 3) = Text1(1).Text
    xlsheet.Cells(5, 4) = Text1(2).Text
    xlsheet.Cells(5, 5) = Text1(3).Text
    xlwbook.Save
    
End Sub

Private Sub Form_Load()
    Set xlwbook = xl.Workbooks.Open("c:\temp\csv_1000_6_10.xls")
    Set xlsheet = xlwbook.Sheets.Item(2)

  
End Sub

Private Sub Form_Unload(Cancel As Integer)
'don't forget to do this or you'll not be able to open
'book1.xls again, untill you restart you pc.
    
    xl.ActiveWorkbook.Close True, "c:\temp\csv_1000_6_10.xls"
    xl.Quit
   
    Set xlwbook = Nothing
    Set xl = Nothing
End Sub

This does work to change the data on the sheet, but how do I get the graph to refresh with the new data?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.