|
-
Mar 2nd, 2001, 11:40 AM
#1
Thread Starter
Junior Member
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.
-
Mar 2nd, 2001, 12:13 PM
#2
Hyperactive Member
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
-
Sep 13th, 2005, 09:08 PM
#3
New Member
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
-
Sep 13th, 2005, 10:25 PM
#4
Hyperactive Member
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
-
Sep 13th, 2005, 11:32 PM
#5
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.
-
Sep 13th, 2005, 11:42 PM
#6
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 Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API 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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|