简体   繁体   English

在Excel数据源SQL查询中使用TableName而不是命名范围

[英]Using a TableName instead of Named Range in Excel datasource SQL Query

In Excel VBA, I am using Excel as datasource for some queries. 在Excel VBA中,我使用Excel作为某些查询的数据源。 I am using the query as 我正在使用查询

SQL = "Select * from   [NameRange1]"   - This works

But, I want to use a table name instead of Namerange(Excel 2007 Tables). 但是,我想使用表名而不是Namerange(Excel 2007 Tables)。 How do I use that? 如何使用? I tried "select * from [Table1]" and I also tried creating a Namerange for this table1 and it didn't work either.. 我尝试了"select * from [Table1]"并且还尝试为该table1创建一个Namerange,但它也不起作用。

any ideas please? 有什么想法吗?

You don't say whether you're using DAO or ADO to connect, but I don't think it matters. 您没有说要使用DAO还是ADO进行连接,但是我认为这并不重要。 I don't think it's possible to refer to a Table. 我认为不可能引用表。 All the documentation I've seen lists three types of ranges: an entire sheet [Sheet1$], a named range[NameRange1], or an unnamed range [Sheet1$A1:B10]. 我所见过的所有文档都列出了三种类型的范围:整个工作表[Sheet1 $],命名范围[NameRange1]或未命名范围[Sheet1 $ A1:B10]。

I am able to give an Excel 2010 table a named range that includes the header and that works just like any other named range, and it changes size with the addition of rows. 我能够给Excel 2010表一个包含标题的命名范围,并且该命名范围的工作方式与任何其他命名范围一样,并且它通过添加行来更改大小。 Make sure that if it's a sheet-level named range you do it like [Sheet1$NameRange1]. 确保它是工作表级别的命名范围,您可以像[Sheet1 $ NameRange1]一样进行操作。

The best information I found on doing it with ADO is here: http://www.xtremevbtalk.com/showthread.php?t=217783 我发现有关使用ADO的最佳信息是在这里: http ://www.xtremevbtalk.com/showthread.php?t= 217783

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM