Solved

sql statement of MS Excel

Posted on 2002-04-15
5
201 Views
Last Modified: 2012-05-04

hi!again....

i need to know code to access MS Excel and write  a sql statement to select some data.

any library that need?

can i use the the ADO to do this?just like i do on MS Access.

select field
from table
where ....

what to replace the field,table....

 
0
Comment
Question by:iven
  • 2
  • 2
5 Comments
 
LVL 142

Accepted Solution

by:
Guy Hengel [angelIII / a3] earned 15 total points
ID: 6941475
With ADO you can use, just connect to the file using the ODBC driver you have certainly installed for excel.
Use the DBQ=path\filename.xls in the connection string, and in the select would be
SELECT * FROM <sheetname>
or eventually
SELECT * FROM <sheetname>$

CHeers
0
 
LVL 1

Expert Comment

by:kavithag
ID: 6941694
You need to use the ADO diver for query and Microsoft Excel 9.0 library to display the selected data into Excel.
0
 

Author Comment

by:iven
ID: 6944124
angellll

hi!
can u show me some example?
thanx!
0
 

Author Comment

by:iven
ID: 6944194
angellll,

i use DAO to do this:

filepath = "d:\testing.xls"
Set db = OpenDatabase(filepath, False, False, "Excel 8.0;HDR=yes;")
Set rs = db.OpenRecordset("select * from sheet1")

what is the problem of this?when i run this sql,the error
"...could not find the object "sheet1"...."
0
 
LVL 142

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 6944200
as I mentionned above, try sheet$

CHeers
0

Featured Post

Ransomware: The New Cyber Threat & How to Stop It

This infographic explains ransomware, type of malware that blocks access to your files or your systems and holds them hostage until a ransom is paid. It also examines the different types of ransomware and explains what you can do to thwart this sinister online threat.  

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

821 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question