vb 怎么把ACCESS数据库里面的指定一个表导入到EXCEL里面去啊???

来源:百度知道 编辑:UC知道 时间:2024/06/18 04:28:20
急啊
请高手指教 跪着先谢谢了
最好有源代码的哦(还需不需要做一些设置啊?) 非常非常的感谢 (数据库连接方面没有问题了)

Private Sub CmdOutput_Click()
Dim cn As New ADODB.Connection
Dim rs As New ADODB.Recordset
Dim sql As String

cn.Open "provider=microsoft.jet.oledb.4.0;data source=d:\gift\gift.mdb"

sql = "select * from [ly_gift]"

rs.Source = sql
Set rs.ActiveConnection = cn
rs.LockType = adLockOptimistic
rs.CursorLocation = adUseClient
rs.Open sql, cn

If rs.RecordCount < 1 Then
MsgBox "没有数据导出", vbOKOnly + vbCritical, "错误提示"
Else

If Dir("C:\Excel", vbDirectory) = "" Then
MkDir ("C:\Excel")
End If

If Dir("C:\Excel") <> "" Then
Kill "C:\Excel\gift.xls"
End If
End If

Dim i As Integer
Dim j As Integer
Dim xlExcel As New Excel.Application
Dim xlBook As New Excel.Workbook
Dim xlSheet As New E