Solved

Excel chart OLE problem

Posted on 1997-12-07
2
294 Views
Last Modified: 2008-02-26
I want to draw a chart by using ole and excel chart, the
data value to be plotted are in a dbgrid
does anyone know how to use these values in dbgrid and
draw a chart...I don't want to go to excel sheet.. but
from dbgrid in Vb to excel chart...........

0
Comment
Question by:zakman
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 

Author Comment

by:zakman
ID: 1444135
Edited text of question
0
 
LVL 4

Accepted Solution

by:
rantanen earned 100 total points
ID: 1444136
zakman,

here's a sub which takes a column in DBGrid and makes an Excel bar chart of the data

Private Sub MakeBarChart(nDBGridCol As Integer, nExcelCol As Integer)
    Dim objXLsheet As Object
    Dim objRange As Object
    Dim objChart As Object

    Dim nPoints As Integer

    Form1.MousePointer = vbHourglass
     
    ' Create a Worksheet Object:
    Set objXLsheet = CreateObject("Excel.Sheet")

    ' Insert data into an Excel column from a DBGrid's column
    nExcelCol = 1
    nDBGridCol = 1
    With Form1.DBGrid1
        .Col = nDBGridCol
        Data1.Recordset.MoveFirst
        nPoints = 1
        While Not Data1.Recordset.EOF
            objXLsheet.Cells(nPoints, nExcelCol).Value = CInt(DBGrid1.Text)
            Data1.Recordset.MoveNext
            nPoints = nPoints + 1
        Wend
    End With
           
    ' Add a ChartObject to the worksheet:
    Set objChart = objXLsheet.ChartObjects.Add(100, 100, 200, 200)

    ' Assign the column created above as a series for the chart:
    objChart.Chart.SeriesCollection.Add objXLsheet.Columns(nExcelCol), xlColumns

    ' Make Excel Visible:
    objXLsheet.Application.Visible = True
    DoEvents

    ' Save the Worksheet to disk.
    objXLsheet.Parent.SaveAs "C:\XLCHART.XLS"

    ' Close this instance of Excel:
    objXLsheet.Application.Quit
    MousePointer = vbArrow
End Sub

0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…

728 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question