VB控制EXCEL并使用SQL语句


Dim cn As ADODB.Connection
Set cn = New ADODB.Connection
Dim x, l As Long
Dim sql As String

x = 2
With cn
.Provider = "Microsoft.Jet.OLEDB.4.0"
.ConnectionString = "Data Source=" & wkname & ";" & _
"Extended Properties=Excel 8.0;"
.Open
End With
Dim rs As ADODB.Recordset
Set rs = New ADODB.Recordset
rs.ActiveConnection = cn

If tablename1.Text <> "" Then


            rs.Open "select * from " & "[" & tablename1.Text & "$]", cn, 1, 3 

posted @ 2007-01-23 14:57  attitudedecidesall  Views(268)  Comments(0Edit  收藏  举报