4

I am reading data from an Excel 2007 spreadsheet using ADO. Setting up the connection is easy:

Dim ado As ADODB.Connection
Set ado = CreateObject("ADODB.Connection")
ado.ConnectionString = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=myFilename.xlsx;Extended Properties=""Excel 12.0 Xml;HDR=NO;IMEX=1"";"
ado.Open

I can call ado.OpenSchema without any trouble on this object. However, when I try to query the data:

Dim rs As ADODB.recordSet
Set rs = ado.Execute("SELECT * FROM [Current Work Load$]")

I simply get a table full of Nulls.

This is mentioned as an issue on the Microsoft Support site - but I have explicitly enabled "Import Mode" (as you can see in the code above - IMEX=1).

4 Answers 4

3

The Execute method does not return any records as it is for action queries. Your might want to try the OpenRecordset method.

Dim rs As ADODB.recordSet
Set rs = ado.OpenRecordset("SELECT * FROM [Current Work Load$]")
Sign up to request clarification or add additional context in comments.

Comments

2

I've found the ADO connection strings here are unbelievably picky. I've gotten reading the spreadsheets to work but with a slightly different connection string:

Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + fileName + @";Extended Properties="Excel 12.0;IMEX=1";

(I don't have the XML after the Excel 12.0 declaration).

1 Comment

or the HDR=NO; which depends on whether there is one.
1

SpreadsheetGear for .NET can read Excel workbooks and enables you to access any cells without the kinds of issues / limatations you can run into with ADO.

You can see live C# & VB samples here and download the free trial here.

Disclaimer: I own SpreadsheetGear LLC

Comments

1

As well as using IMEX=1 in the connection string, you need to review a couple of registry keys. For more details, see this answer on SO.

2 Comments

Link broken. Is there another source for the registry key solution?
@sigil: I've changed the link to another SO answer, which has the same content as the aforementioned blog post (minus the comments).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.