Solved

Create and populate an Excel file from Visual Basic6

Posted on 2004-09-29
3
128 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

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Best way to parse out a json string in VB6? 10 174
Run code from text file in vb 1 65
vb6 connector to SQL Server 2 37
IF ELSE Statement in Excel Macro VBA 16 65
Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
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…

803 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