Solved

Create and populate an Excel file from Visual Basic6

Posted on 2004-09-29
3
126 Views
Last Modified: 2010-05-02
I need to create an Excel file from Visual Basic, in case the file already exists I need to append from VB. In the Excel file I have two columns I need to populate, First_name and last_name.
How do I do this from Visual Basic, what objects I need to use and what the sysntax might might be?
Thank you
0
Comment
Question by:Mensana
3 Comments
 
LVL 16

Expert Comment

by:jimbobmcgee
Comment Utility
Use .CSV files instead of an Excel .XLS format; both are readable by Excel.

Try:

    Open "x:\mypath\myfile.csv" for output as #1

       For i = Lbound(First_Name()) to Ubound(First_Name())   'or some other loop counter
       
           Print #1, First_name(i) & "," & Last_name(i)
       
       Next i

    Close #1
0
 
LVL 5

Accepted Solution

by:
jkwasson earned 200 total points
Comment Utility
I agree with jimbob :)

but if, for some reason, you really wanted to use Excel, you would want to add a reference to your vb project for the Microsoft Excel Objects. This would allow you to use the Excel Object Model to control excel from your VB program. You can learn more about it here:

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dv_wrcore/html/wrconExcelObjectModelOverview.asp
0
 
LVL 1

Author Comment

by:Mensana
Comment Utility
It had to be an Excel file. Thanks for the link. It helped.
0

Featured Post

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

Suggested Solutions

Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

772 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

10 Experts available now in Live!

Get 1:1 Help Now