Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to convert a table to .xls in VB6

Status
Not open for further replies.

LiLgUrL

Technical User
Feb 9, 2003
59
CA
i made a program in access and im converting it using vb6. but i encountered a problem --- in access it's easy to convert a table to .xls format - but in vb i dont know if it's possible. if so... anyone can teach me how? thanks!

 
There are many examples on reading and writing to Excel and of how to make a recordset in VB6
You have to enable the Excel thing in References to be able to use the routines for that.
You have to read the cells in each row and write them to a recordset in VB6.
 
Or even easier (IMO):
Code:
  Dim conX As ADODB.Connection
  Set conX = New ADODB.Connection
  conX.Open "DSN=Excel Files;DBQ=C:\My Documents\Book1.xls;" _
    & "DefaultDir=C:\My Documents;DriverId=22;" _
    & "MaxBufferSize=2048;PageTimeout=5;"
  conX.Execute "SELECT Field1, Field2, Field3 INTO MyTable " _
    & "IN 'C:\My Documents\db1.mdb' FROM [Sheet1$]"
  conX.Close
  Set conX = Nothing

Andy
"Logic is invincible because in order to combat logic it is necessary to use logic." -- Pierre Boutroux
"A computer program does what you tell it to do, not what you want it to do." -- Greer's Third Law
 
Hi Andy! What I really want is to convert my table from .mdb to .xls --- and your code will convert the .xls and create a table to .mdb right?
 
Hi tedsmith! Can you please guide me on how to do it?

DoCmd.OutputTo acOutputTable, "Table1", "MicrosoftExcel(*.xls)", "\MyTable\" & "WorkSheet1.xls"

This is the code i used in access to convert a table from .mdb to .xls

Is there any equivalent code of this using VB6?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top