PC Review


Reply
Thread Tools Rate Thread

ADO SQL syntax for extracting specific columns from Excel to Excel

 
 
=?Utf-8?B?U3Bpa2U=?=
Guest
Posts: n/a
 
      1st May 2007
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 With Quote
 
 
 
 
=?Utf-8?B?dXJrZWM=?=
Guest
Posts: n/a
 
      1st May 2007
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 With Quote
 
=?Utf-8?B?U3Bpa2U=?=
Guest
Posts: n/a
 
      2nd May 2007
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 With Quote
 
=?Utf-8?B?U3Bpa2U=?=
Guest
Posts: n/a
 
      2nd May 2007
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 With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Import specific columns from Excel Rafi Microsoft Access External Data 1 1st Feb 2008 08:10 PM
Syntax for looping through rows and columns in Excel Curious Microsoft Excel Programming 6 7th Aug 2007 09:55 PM
Extracting specific Excel data into word =?Utf-8?B?Tmljb2xlIEtuYXBw?= Microsoft Word Document Management 3 12th Jul 2007 10:18 PM
extracting mailitem.body text to Excel columns Junoon Microsoft Outlook VBA Programming 3 20th Apr 2006 05:45 AM
Transfer Data to specific columns in Excel Tamer Seoud Microsoft Access Queries 2 18th Dec 2003 03:51 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 05:37 AM.