Solved

Create and populate an Excel file from Visual Basic6

Posted on 2004-09-29
3
127 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
ID: 12180877
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
ID: 12181133
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
ID: 12227689
It had to be an Excel file. Thanks for the link. It helped.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
String manipulation in Visual Basic 7 59
Macro Excel - Multiple If conditions 2 64
how to know if my Checkbox is True in VB6.0? 9 40
vbModal 12 35
The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
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…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
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…

920 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

11 Experts available now in Live!

Get 1:1 Help Now