Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5
Default Accessing a sheet-level named range through ADO


Hello,

I am trying to retrieve data from a workbook (xlsx) through ADO.

It works fine with ranges and workbook-level named ranges.

For instance, say that the workbook Hello.xlsx contains a range named "AnyData"
(defined at workbook level). This code works fine:

Const File = "C:\Temp\Hello.xlsx"
Dim Rs As New ADODB.Recordset
Dim Conn As New ADODB.Connection
Conn.Open "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" & File & _
";Extended Properties=""Excel 12.0;HDR=NO;IMEX=1"""
Rs.Open "SELECT * FROM AnyData", Conn

Now, suppose that "AnyData" is a worksheet-level name (attached to Sheet1, for
instance). How do you pass Sheet1!AnyData to the SELECT query?

I've tried :

Rs.Open "SELECT * FROM [Sheet1$AnyData]", Conn

.... but this query is rejected by the Jet engine.

If you do as if AnyData were a workbook-level name :

Rs.Open "SELECT * FROM AnyData", Conn

.... it works fine, but in this case, how can I access for instance another
"AnyData" named range which would be attached to another worksheet (say for
instance Sheet2!AnyData)?

Thanks !


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5
Default Accessing a sheet-level named range through ADO


Solved !

The right syntax is : "SELECT * FROM [Sheet1$]AnyData"

Ahasverus a écrit :

Hello,

I am trying to retrieve data from a workbook (xlsx) through ADO.

It works fine with ranges and workbook-level named ranges.

For instance, say that the workbook Hello.xlsx contains a range named
"AnyData" (defined at workbook level). This code works fine:

Const File = "C:\Temp\Hello.xlsx"
Dim Rs As New ADODB.Recordset
Dim Conn As New ADODB.Connection
Conn.Open "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" & File & _
";Extended Properties=""Excel 12.0;HDR=NO;IMEX=1"""
Rs.Open "SELECT * FROM AnyData", Conn

Now, suppose that "AnyData" is a worksheet-level name (attached to
Sheet1, for instance). How do you pass Sheet1!AnyData to the SELECT query?

I've tried :

Rs.Open "SELECT * FROM [Sheet1$AnyData]", Conn

... but this query is rejected by the Jet engine.

If you do as if AnyData were a workbook-level name :

Rs.Open "SELECT * FROM AnyData", Conn

... it works fine, but in this case, how can I access for instance
another "AnyData" named range which would be attached to another
worksheet (say for instance Sheet2!AnyData)?

Thanks !


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 10,593
Default Accessing a sheet-level named range through ADO

Odd, it was how you had it in 2003 with Jet provider and Excel 8.

--
HTH

Bob

(there's no email, no snail mail, but somewhere should be gmail in my addy)

"Ahasverus" wrote in message
...

Solved !

The right syntax is : "SELECT * FROM [Sheet1$]AnyData"

Ahasverus a écrit :

Hello,

I am trying to retrieve data from a workbook (xlsx) through ADO.

It works fine with ranges and workbook-level named ranges.

For instance, say that the workbook Hello.xlsx contains a range named
"AnyData" (defined at workbook level). This code works fine:

Const File = "C:\Temp\Hello.xlsx"
Dim Rs As New ADODB.Recordset
Dim Conn As New ADODB.Connection
Conn.Open "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" & File & _
";Extended Properties=""Excel 12.0;HDR=NO;IMEX=1"""
Rs.Open "SELECT * FROM AnyData", Conn

Now, suppose that "AnyData" is a worksheet-level name (attached to
Sheet1, for instance). How do you pass Sheet1!AnyData to the SELECT
query?

I've tried :

Rs.Open "SELECT * FROM [Sheet1$AnyData]", Conn

... but this query is rejected by the Jet engine.

If you do as if AnyData were a workbook-level name :

Rs.Open "SELECT * FROM AnyData", Conn

... it works fine, but in this case, how can I access for instance
another "AnyData" named range which would be attached to another
worksheet (say for instance Sheet2!AnyData)?

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
Accessing data stored in the worksheet (named range) in .xla file noiseberg Excel Programming 1 September 26th 07 07:03 PM
accessing named range greg Excel Programming 13 July 12th 07 01:49 AM
Named range in a sheet referred to from another sheet Lluis Escude Excel Programming 2 June 28th 06 12:23 PM
Access a worksheet level named range with Refers To like "=5". Jeremy Gollehon[_3_] Excel Programming 2 May 15th 06 10:56 PM
Why, when I create workbook-level name does it jump it to Sheet-level ? Charles Jordan Excel Programming 1 November 5th 03 08:43 PM


All times are GMT +1. The time now is 06:47 AM.

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"