access文件转换成EXL文件
我的VB6的ACCESS文件里的2个表想导成EXL文件,请高手帮忙。非常感谢
[解决办法]
经实际测试,以下代码数据库和Excel之间互相导入导出,完全成功!
Private Sub Command1_Click()
'access导出到excel
Dim db As New ADODB.Connection
Dim sPath As String
db.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=E:\Temp\Test\db1.mdb Persist Security Info=False"
sPath = App.Path + "\backup.xls"
If Dir(sPath) <> "" Then
Kill sPath
Else
Call db.Execute("select * into Sheet1 In '" & sPath & "' 'excel 8.0;' from 表1")
MsgBox "导出成功", vbOKOnly, "提示"
End If
db.Close
Set db = Nothing
End Sub
Private Sub Command2_Click()
'从excel导出到 access
Dim db As New ADODB.Connection
Dim sPath As String
db.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=E:\Temp\Test\db1.mdb;Persist Security Info=False"
sPath = App.Path + "\backup.xls"
Call db.Execute("select * into Table4 From [Sheet1$] In '" & sPath & "' 'excel 8.0;'")
db.Close
Set db = Nothing
End Sub