ado.net - How do I access an Excel named table via ADO/ODBC? -


i have workbook multiple sheets, , have created named tables (not ranges) in work book. illustrative purposes, these table names tbla, tblb, , tblc. unable find way query these tables via ado or odbc. can access named ranges, not work needs.

thanks!

i don't know if can done directly interested see if comes working method. getschema collection of ado seems pick sheetnames , named ranges not listobjects named tables are. below workaround means opening excel find header/data range of table. it's pointless using ado or similar can copy data directly suppose convert named range before saving one-off task?

option explicit  sub test() dim wb workbook, ws worksheet, strexcelfile string, strsheetname string dim strtablename string, objlistobj listobject, headerrange string dim strsql string, datarange string  strexcelfile = "c:\users\osknows\desktop\new folder\test.xlsm" strsheetname = "sheet1" strtablename = "tablename"   set wb = getobject(strexcelfile) 'filepath & filename set ws = wb.sheets(strsheetname) 'sheetname set objlistobj = ws.listobjects(strtablename) 'table name  'get range of table headerrange = objlistobj.headerrowrange.address datarange = objlistobj.databodyrange.address  'write data directly if required thisworkbook     sheet1     '.range(headerrange).value = ws.range(headerrange).value     '.range(datarange).value = ws.range(datarange).value     end end  'or use adodb bit pointless now! dim cnn1 new adodb.connection dim rst1 new adodb.recordset  cnn1.open "provider=microsoft.ace.oledb.12.0;" & _     "data source=" & strexcelfile & ";" & _     "extended properties=""excel 12.0;hdr=no;imex=1"";"  strsql = "select * [" & strsheetname & "$" & replace(datarange, "$", "") & "];" rst1.open strsql, cnn1, adopenstatic, adlockreadonly   'tidy set objlistobj = nothing set ws = nothing wb.close set wb = nothing end sub 

Comments

Popular posts from this blog

c++ - How do I get a multi line tooltip in MFC -

asp.net - In javascript how to find the height and width -

c# - DataTable to EnumerableRowCollection -