ActiveSheet.QueryTables.Add

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I am importing a CSV file and want to be selective in my data. I need to
bypass any record that does not have a char "V" in the specified column. The
above subject is also the standard QueryTables.Add statement. Any
suggestions?
 
Hello,

ADO stands for ActiveX Data Objects and is a technology currently supported
by Microsoft that enables you to deliver a SQL string to retrieve and/or
modify a wide variety of files including: MS-Access, MS-Excel, text files,
other types of databases, such as Oracle, and even MS-Word tables.

There is actually a lot of information out there if you google it, or seach
Microsoft's web site, but a good place to start is the link below:

http://www.erlandsendata.no/english/index.php?t=envbadac

Copy the above into your browser and GO.

HERE are a few others to try:

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/ado270/htm/mdrefadoprovinfo.asp

http://support.microsoft.com/default.aspx?scid=kb;en-us;257819

HTH/
 
Rick said:
I am importing a CSV file and want to be selective in my data. I need to
bypass any record that does not have a char "V" in the specified column.
The above subject is also the standard QueryTables.Add statement. Any
suggestions?

Rick: Unless I'm misunderstanding something, you can be selective with a
QueryTables.Add statement. You pass a SQL statement to QueryTables.Add and
use the SQL statement to limit the records it imports. Here's an example:

Sub AddQTFromCSV()

Dim sConn As String
Dim sSQL As String

sConn = "ODBC;DSN=Text Files;" & _
"DefaultDir=C:\Documents and Settings\Dick\My Documents;" & _
"DriverId=27;MaxBufferSize=2048;PageTimeout=5;"

sSQL = "SELECT Field1, Field2, Field3, Field4, Field5" & _
" FROM `C:\Documents and Settings\Dick\My Documents`\Book1.csv" & _
" WHERE (Field2='V')"

With Sheet3.QueryTables.Add(sConn, Sheet3.Range("A1"), sSQL)
.Refresh
End With

End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top