Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion GroupsVB SyntaxEnterprise DevelopmentDatabase AccessControlsCOMWin APICrystal ReportDeploymentGeneralGeneral 2
Related Topics
VB.NET / ASP.NETMS SQL ServerMS AccessOther Database ProductsMore Topics ...

VB Forum / Database Access / December 2006



Tip: Looking for answers? Try searching our database.

Open and read excel worksheet using ADO

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Andrew - 22 Dec 2006 01:40 GMT
Hi Guys,

I'm new at ADO and really wanting some sample code of how to use it to open
a known xls, and get the list of worksheet names. Then once a worksheet name
is known, how to get the info from it. Also, can I get the cell formatting
info as well? or just the contents?

Many thanks in Advance

Andrew
Paul Clement - 22 Dec 2006 16:31 GMT
¤ Hi Guys,
¤
¤ I'm new at ADO and really wanting some sample code of how to use it to open
¤ a known xls, and get the list of worksheet names. Then once a worksheet name
¤ is known, how to get the info from it. Also, can I get the cell formatting
¤ info as well? or just the contents?

ADO can provide database related information but nothing concerning cell formatting. Below is an
example:

Dim cnn As New ADODB.Connection
Dim rsSchema As New ADODB.Recordset
Dim fld As ADODB.Field

On Error Resume Next

cnn.Open "Provider=Microsoft.Jet.OLEDB.4.0;" & _
  "Data Source=C:\Test Files\Book20.xls;Extended Properties=Excel 8.0;"

'Open the tables schema rowset
Set rsSchema = cnn.OpenSchema(adSchemaTables, Array(Empty, Empty, Empty, Empty))
'Open the columns schema rowset
'Set rsSchema = cnn.OpenSchema(adSchemaColumns, Array(Empty, Empty, "Sheet1", Empty))

'Loop through the results and print the names in the Immediate window
While Not rsSchema.EOF
   
   For Each fld In rsSchema.Fields
       Debug.Print fld.Name & " : " & fld.Value
   Next fld
   
   rsSchema.MoveNext
Wend
 
rsSchema.Close
cnn.Close

Paul
~~~~
Microsoft MVP (Visual Basic)
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2009 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.