Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Create and populate an Excel file from Visual Basic6

Posted on 2004-09-29
3
Medium Priority
?
135 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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 600 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

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

Question has a verified solution.

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

If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
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…
Suggested Courses

705 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