Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 33
Default Problem accessing an Excel file from ADO

Hello !

I have an Excel 2003 file where I programmed a VBA application.

A one point, the content of another Excel file has to be read and
processed. For some reason, I decided to use some code I had developed
in an Access application to import an Excel sheet data.

The code is using an ADODB connection and recordset and the data is
retreived with an SQL statement.

In short, the code looks like this :

Set cnn = New ADODB.Connection
Set rst = New ADODB.Recordset

cnn.Open "Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=" & strFile & ";" & _
"Extended Properties='Excel 8.0;HDR=YES'"

rst.Open "SELECT * FROM [Sheet1$]", cnn, adOpenStatic, adLockReadOnly

NB: strFile is a valid and existing file, Sheet1 is an existing sheet
within strFile.

The problem is :

- if that file is already open, everything works fine. :-)

- if the file is not, I get the following error on the rst.Open
statement : 8004005 : DB Engine cannot find 'Sheet1$'

I'm using Office 2003, ADO 2.8 library


The same code works in Access 2002 even with excel not running.


While I can manage to open the file in Excel before and close it after
use, I'd prefer to fix the problem instead of working around it.

Any ideas ?

Thanks


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 33
Default Solved: Problem accessing an Excel file from ADO

Well..

I just discovered that, for some mysterious reason, the Excel file was
in 3.0 format ! 8-o

Opening the file in Excel 2003 and saving it again invoked the
conversion dialog. Once saved in the newer format, everything works
fine with the rst.Open statement.

I guess that once loaded in memory, the file was not in 3.0 format,
which explains why it worked only when the file was open.



Michel S. a émis l'idée suivante :
Hello !

I have an Excel 2003 file where I programmed a VBA application.

A one point, the content of another Excel file has to be read and processed.
For some reason, I decided to use some code I had developed in an Access
application to import an Excel sheet data.

The code is using an ADODB connection and recordset and the data is retreived
with an SQL statement.

In short, the code looks like this :

Set cnn = New ADODB.Connection
Set rst = New ADODB.Recordset

cnn.Open "Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=" & strFile & ";" & _
"Extended Properties='Excel 8.0;HDR=YES'"

rst.Open "SELECT * FROM [Sheet1$]", cnn, adOpenStatic, adLockReadOnly

NB: strFile is a valid and existing file, Sheet1 is an existing sheet within
strFile.

The problem is :

- if that file is already open, everything works fine. :-)

- if the file is not, I get the following error on the rst.Open statement :
8004005 : DB Engine cannot find 'Sheet1$'

I'm using Office 2003, ADO 2.8 library

The same code works in Access 2002 even with excel not running.

While I can manage to open the file in Excel before and close it after use,
I'd prefer to fix the problem instead of working around it.

Any ideas ?

Thanks



Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
problem accessing Pivot table Excel 2007 ann Excel Worksheet Functions 0 February 19th 09 05:42 AM
accessing word file from an excel file surena Excel Programming 0 May 23rd 06 02:50 PM
asp having problem accessing excel 2002 Roel[_3_] Excel Programming 0 March 22nd 06 05:58 AM
Multiple accessing of an excel file [email protected] Excel Discussion (Misc queries) 5 February 26th 06 06:56 PM
accessing .mpp file using excel VBA macros amit[_3_] Excel Programming 0 November 10th 05 09:44 AM


All times are GMT +1. The time now is 01:26 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"