Sub excel连接数据库()
Dim Con As New ADODB.Connection
Dim strCon As String
Dim rs As ADODB.Recordset '设置记录集
Dim i, t
t = Timer
strCon = " Provider=Microsoft.ACE.OLEDB.12.0;" & _
"Data Source= D:\平台\报表\账户流水.xlsx" & _
";Extended Properties=""Excel 12.0;HDR=True"";"
strSQL = "select * from [账户流水$]"
Con.Open strCon
Set rs = Con.Execute(strSQL)
For i = 0 To rs.Fields.Count - 1 '逐个字段
Cells(3, i + 3) = rs.Fields(i).Name '取字段名 字头放置在cell(3,3)
Next i
Range("c4").CopyFromRecordset rs
rs.Close
Con.Close
Set rs = Nothing
Set C
Dim Con As New ADODB.Connection
Dim strCon As String
Dim rs As ADODB.Recordset '设置记录集
Dim i, t
t = Timer
strCon = " Provider=Microsoft.ACE.OLEDB.12.0;" & _
"Data Source= D:\平台\报表\账户流水.xlsx" & _
";Extended Properties=""Excel 12.0;HDR=True"";"
strSQL = "select * from [账户流水$]"
Con.Open strCon
Set rs = Con.Execute(strSQL)
For i = 0 To rs.Fields.Count - 1 '逐个字段
Cells(3, i + 3) = rs.Fields(i).Name '取字段名 字头放置在cell(3,3)
Next i
Range("c4").CopyFromRecordset rs
rs.Close
Con.Close
Set rs = Nothing
Set C