Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 140
Default ADO SQL syntax for extracting specific columns from Excel to Excel

I will be grateful for the SQL syntax to use in ADO to extract specific
columns from an Excel workbook, i need to extract say column headed "ABC"and
column headed "LMN" in a closed workbook.

Any help will be gratefully received
--
with kind regards

Spike
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 131
Default ADO SQL syntax for extracting specific columns from Excel to Excel

Something like this:


Sub ADOTest()

Const adOpenStatic = 3
Const adLockOptimistic = 3
Const adCmdText = &H1

Set Cnn = CreateObject("ADODB.Connection")
Set Rs = CreateObject("ADODB.Recordset")

Cnn.Open "Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=C:\Test.xls;" & _
"Extended Properties=""Excel 8.0;HDR=Yes;"";"

Rs.Open "Select ABC, LMN FROM [Sheet1$]", _
Cnn, adOpenStatic, adLockOptimistic, adCmdText

Do Until Rs.EOF
Debug.Print Rs.Fields.Item("ABC"), _
Rs.Fields.Item("LMN")
Rs.MoveNext
Loop

End Sub


--
urkec


"Spike" wrote:

I will be grateful for the SQL syntax to use in ADO to extract specific
columns from an Excel workbook, i need to extract say column headed "ABC"and
column headed "LMN" in a closed workbook.

Any help will be gratefully received
--
with kind regards

Spike

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 140
Default ADO SQL syntax for extracting specific columns from Excel to E

Thank you very much for that works fine but if the column heading is two
separate words does not like it and get an error message "syntax error,
(missing operator) in query expression 'Gross Assets"".

How do i get around this.
--
with kind regards

Spike


"urkec" wrote:

Something like this:


Sub ADOTest()

Const adOpenStatic = 3
Const adLockOptimistic = 3
Const adCmdText = &H1

Set Cnn = CreateObject("ADODB.Connection")
Set Rs = CreateObject("ADODB.Recordset")

Cnn.Open "Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=C:\Test.xls;" & _
"Extended Properties=""Excel 8.0;HDR=Yes;"";"

Rs.Open "Select ABC, LMN FROM [Sheet1$]", _
Cnn, adOpenStatic, adLockOptimistic, adCmdText

Do Until Rs.EOF
Debug.Print Rs.Fields.Item("ABC"), _
Rs.Fields.Item("LMN")
Rs.MoveNext
Loop

End Sub


--
urkec


"Spike" wrote:

I will be grateful for the SQL syntax to use in ADO to extract specific
columns from an Excel workbook, i need to extract say column headed "ABC"and
column headed "LMN" in a closed workbook.

Any help will be gratefully received
--
with kind regards

Spike

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 140
Default ADO SQL syntax for extracting specific columns from Excel to E

Further to my earlier post i have sorted it by putting the headings in square
bracketd.

Many thanks for your help works a dream
--
with kind regards

Spike


"Spike" wrote:

Thank you very much for that works fine but if the column heading is two
separate words does not like it and get an error message "syntax error,
(missing operator) in query expression 'Gross Assets"".

How do i get around this.
--
with kind regards

Spike


"urkec" wrote:

Something like this:


Sub ADOTest()

Const adOpenStatic = 3
Const adLockOptimistic = 3
Const adCmdText = &H1

Set Cnn = CreateObject("ADODB.Connection")
Set Rs = CreateObject("ADODB.Recordset")

Cnn.Open "Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=C:\Test.xls;" & _
"Extended Properties=""Excel 8.0;HDR=Yes;"";"

Rs.Open "Select ABC, LMN FROM [Sheet1$]", _
Cnn, adOpenStatic, adLockOptimistic, adCmdText

Do Until Rs.EOF
Debug.Print Rs.Fields.Item("ABC"), _
Rs.Fields.Item("LMN")
Rs.MoveNext
Loop

End Sub


--
urkec


"Spike" wrote:

I will be grateful for the SQL syntax to use in ADO to extract specific
columns from an Excel workbook, i need to extract say column headed "ABC"and
column headed "LMN" in a closed workbook.

Any help will be gratefully received
--
with kind regards

Spike

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
Extracting specific text from another cell. Doug Excel Discussion (Misc queries) 4 July 1st 09 06:05 PM
Importing data from access to excel to a specific columns ielmrani via OfficeKB.com Links and Linking in Excel 1 September 24th 08 09:52 AM
extracting specific rows wynand Excel Discussion (Misc queries) 6 January 29th 08 01:15 PM
extracting specific rows wynand Excel Discussion (Misc queries) 9 January 29th 08 11:33 AM
I need help -extracting specific data Karlos[_2_] Excel Programming 0 November 8th 05 02:47 PM


All times are GMT +1. The time now is 09:14 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"