|
-
Aug 3rd, 2008, 08:45 AM
#1
Thread Starter
New Member
VB6 to Excel and back???
What is the best way to read/write data back and forth from Visual Basic 6 and Excel? I know how to make Visual Basic create excel spreadsheets with the information I need in the correct spots. Shown below:
Code:
Set oExcel = CreateObject("Excel.Application")
Set oBook = oExcel.Workbooks.Add
Set oSheet = oBook.Worksheets(1)
oSheet.Range("A1").Value = LastName.Text & "_" & FirstName.Text & "_" & Last4.Text
oSheet.Range("B1").Value = Phase.Text
oSheet.Range("C1").Value = DS.Text
oSheet.Range("D1").Value = RoomNumber.Text
oSheet.Range("E1").Value = "Destination"
oSheet.Range("F1").Value = "LB1"
oSheet.Range("G1").Value = "LB2"
oSheet.Range("H1").Value = "DTOUT"
oSheet.Range("I1").Value = "DTIN"
oBook.SaveAs "C:\Documents and Settings\Brooks\Desktop\Duh\" & LastName.Text & "_" & FirstName.Text & ".xlw"
oExcel.Quit
Now, my question is, how can I get Visual Basic to read and modify this information in the ".xlw" format? Or would it be easier to use ".csv" files? I was going to try to the csv files, but I can't figure out how to get Visual Basic 6 to create the csv files.
Does anyone have any suggestions, sample code or opinions to share?
-
Aug 3rd, 2008, 12:28 PM
#2
Re: VB6 to Excel and back???
If you are using the Excel Object Model already then why go with csv? The EOM will let you read/write to any cell. Just use the Cells collection instead of the Range object and remember to destroy your sheet object variable as well as close and destroy your book variable as it could keep a reference to Excel which will keep it running behind the scenes.
See my Office FAQ (link in sig) for other tips.
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
|