I have a book with several sheets, and each sheet has the same set of named ranges (IE they are attached to the sheet, not to the book).
I want to query based on a named range on any of the sheets. Some sheets have names with no spaces, while others have names with spaces.
I can easily do this for those who don’t have a place, but the syntax for this with spaces eludes me (and google-ing hour).
The named range is “Ingredients,” and one sheet is called “NoSpaces,” the other is “With Spaces”
Here's the code that works great for the No Spaces sheet:
sConnString = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" & dictNewRecipesToCheck(arrKeys(0)) & ";Extended Properties=""Excel 12.0;HDR=No;IMEX=1;"""
strQuery = "Select * from [NoSpaces$Ingredients]"
Set objConn = New ADODB.Connection
Set objRecordSet = New ADODB.Recordset
objConn.Open sConnString
objRecordSet.Open strQuery, objConn
I tried all of the following for the "With spaces" sheet:
strQuery = "Select * from [With Spaces$Ingredients]"
strQuery = "Select * from ['With Spaces'$Ingredients]"
strQuery = "Select * from ['With Spaces$'Ingredients]"
strQuery = "Select * from [With_Spaces$Ingredients]"
" Microsoft Access ...".
, , .
, , .
!
, :
Excel 2007
sConnString = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" & strFileLoc & ";Extended Properties=""Excel 12.0 Macro;HDR=No;IMEX=1;"""
, @shahkalpesh, TABLE_NAME "" ( ).
[NoSpaces $Ingredients] .
sConnString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & strFileLoc & ";Extended Properties=""Excel 8.0;HDR=No;IMEX=1;"""
, @shahkalpesh, TABLE_NAME "NoSpaces $Ingredients" " " ". [NoSpaces $Ingredients] ( ACE).
, , , ['With Spaces' $Ingredients] .
Excel 2013
sConnString = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" & strFileLoc & ";Extended Properties=""Excel 12.0 Macro;HDR=No;IMEX=1;"""
, @shahkalpesh, TABLE_NAME "NoSpaces $Ingredients" "With Spaces $" Ingredients ". [NoSpaces $Ingredients] , ['With Spaces' $Ingredients] .
, , http://db.tt/3lEYm2g1 , Excel 2007, ( ) .