Results 1 to 6 of 6

Thread: Creating Excel Spreadsheets and Graphs

  1. #1
    Junior Member
    Join Date
    Feb 01
    Location
    Tampa
    Posts
    26
    OK Who can help me with creating graphs from Excel in VB?? OR even better yet sending data from Recordsets to a spreadsheet in Excel then creating a graph from that data??

    If you can help me with this you are goooood.

  2. #2
    Hyperactive Member
    Join Date
    Feb 01
    Location
    LoCal
    Posts
    280
    As for how to send data to excel...

    Code:
    dim lngRow as long
    
    dim objExcel as Excel.Application
    dim objWorkBook as Excel.WorkBook
    dim objWorkSheet as Excel.WorkSheet
    
    ' open your excel file
    set objExcel = New Excel.Application
    set objWorkBook = objExcel.WorkBooks.Open ("C:\Excel.xls")
    
    ' this assumes that you have at least one worksheet
    set objWorkSheet = objWorkBook.WorkSheets(1)
    
    ' retrieve the data - i'm assuming you'll put all your code here to open the database connection etc...
    rsData = "SELECT * FROM customers"
    
    ' loop through the data
    Do While Not rsData.EOF
    
       ' increment your row number
       lngRow = lngRow + 1
    
       ' write the information to the worksheet
       objWorkSheet.Cells(lngRow,1) = rsData("name")
       objWorkSheet.Cells(lngRow, 2) = rsData("date")
       objWorkSheet.Cells(lngRow, 3) = rsData("total_purchased")
    
       rsData.MoveNext
    
    Loop
    
    ' save and close the file
    objWorkBook.Save
    objWorkBook.Close
    
    ' cleanup
    set objWorkSheet = nothing
    set objWorkBook = nothing
    set objExcel = nothing
    
    ' close the recordset, etc...
    As for then creating a chart from that data I have nothing to offer. I'd suggest doing a search on the forums since someone has probably already asked that at some point.

    Hope it gives you a starting point...
    Achichincle

    VB6 (VSEE SP5, W2KPro)
    ASP
    HTML

  3. #3
    New Member
    Join Date
    Sep 05
    Posts
    3

    Re: Creating Excel Spreadsheets and Graphs

    Achichincle

    Yes, I'm having a similar problem. Your code that you offered, does this require Excel to be present on the computer to run it, also does this cover all versions of Excel?

    Rgds,
    Dave R

  4. #4
    Hyperactive Member
    Join Date
    Feb 01
    Location
    LoCal
    Posts
    280

    Re: Creating Excel Spreadsheets and Graphs

    Bootie,

    This was from so long ago I don't really remember a whole lot. Looks like I was using the Excel object so yes, it does require that Excel be installed on the machine running the code.

    I've done similar stuff since, but still haven't done any graphing.

    Good luck.
    Achichincle

    VB6 (VSEE SP5, W2KPro)
    ASP
    HTML

  5. #5
    Banned dglienna's Avatar
    Join Date
    Jun 04
    Location
    Center of it all
    Posts
    17,901

    Re: Creating Excel Spreadsheets and Graphs

    Create a macro in Excel, and copy it into a VB app. It may require some alteration before it runs, but it show you what you need to do.

  6. #6
    Super Moderator RobDog888's Avatar
    Join Date
    Apr 01
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    59,465

    Re: Creating Excel Spreadsheets and Graphs

    Moved from Classic VB.
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (VBA, VB 6, VB.NET, C#)
    Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Star Wars Gangsta Rap Reps & Rating PostsVS.NET on Vista (New)Multiple .NET Framework Versions (New)Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel Core 2 Extreme Ed., 2 WD Raptor 10K RPM 150 GB HDs RAID 1, 2 GBs DDR2 667 MHz RAM, 3 Viewsonic 17" LCDs, Windows Vista RTM, IE 7, Office 2007

Posting Permissions

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