Results 1 to 6 of 6

Thread: Creating Excel Spreadsheets and Graphs

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Feb 2001
    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 2001
    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 2005
    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 2001
    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 2004
    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
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    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 (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions 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 i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

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