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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Importing Excel using Visual Basic

Status
Not open for further replies.

sineados

Programmer
Oct 17, 2001
34
IE
Hi,

i want to import an excel spreadsheet using Visual Basic. I have done it in VBA using the docmd.transferspreadsheet but I cant seem to find an easy way of doing it using vb.

anyone any ideas.
thanks,
 
Sorry I should have said I am importing the spreadsheet into a SQL server table.
 
Forget about VB for a moment. You can issue a command to Microsoft SQL Server to import the data for you.

The SQL Command is...

Code:
Select * FROM OPENROWSET( 'Microsoft.Jet.OLEDB.4.0',
'Excel 8.0;Database=[!]C:\test.xls[/!]','SELECT * FROM [[!]Sheet1$[/!]]')

You would use VB to issue the command to SQL Server. And, of course, the command given above only selects the data, but it should be easy enough to modify it so that it inserts the data in to a table.

Hope this helps.

-George

Strong and bitter words indicate a weak cause. - Fortune cookie wisdom
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top