Solved

Excel chart OLE problem

Posted on 1997-12-07
2
288 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
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

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

Introduction I needed to skip over some file processing within a For...Next loop in some old production code and wished that VB (classic) had a statement that would drop down to the end of the current iteration, bypassing the statements that were c…
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

705 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now