1,216
社区成员
发帖
与我相关
我的任务
分享
Set accP = GetObject(strSourcePath, "Access.Application")
dim conn as new adodb.connection
conn.open …………
conn.execute "select * into [excel 8.0;database=d:\123.xls].[导出结果] from tablename"
conn.close
set conn=nothing
'使用须知:1、添加对:Microsoft Access 11.0 Object Library的引用
Option Explicit
Dim accP As Access.Application
Dim strSourcePath As String
Dim strReportPath As String
Dim strObjectName As String
Private Sub Command1_Click()
With cdlP
.DialogTitle = "数据转换"
.InitDir = App.Path & "\数据文件\"
.Filter = "数据文件 (*.mdb)|*.mdb"
.ShowOpen
strSourcePath = .FileName
End With
strObjectName = "TB_Team" '注意,这个名称必须和你选中的数据库中要转换的表格名称一样
strReportPath = App.Path & "\11.xls" '要生成的文件名
If strSourcePath <> "" Then
Set accP = GetObject(strSourcePath, "Access.Application")
accP.DoCmd.OutputTo acOutputTable, strObjectName, acFormatXLS, strReportPath
accP.CloseCurrentDatabase
Set accP = Nothing
End If
End Sub
Private Sub ExportOneTable()
'EXPORTS TABLE IN ACCESS DATABASE TO EXCEL
'REFERENCE TO DAO IS REQUIRED
Dim strExcelFile As String
Dim strWorksheet As String
Dim strDB As String
Dim strTable As String
Dim objDB As Database
'Change Based on your needs, or use
'as parameters to the sub
strExcelFile = "C:\My Documents\MySpreadSheet.xls"
strWorksheet = "WorkSheet1"
strDB = "C:\My Documents\MyDatabase.mdb"
strTable = "MyTable"
Set objDB = OpenDatabase(strDB)
'If excel file already exists, you can delete it here
If Dir(strExcelFile) <> "" Then Kill strExcelFile
objDB.Execute _
"SELECT * INTO [Excel 8.0;DATABASE=" & strExcelFile & _
"].[" & strWorksheet & "] FROM " & "[" & strTable & "]"
objDB.Close
Set objDB = Nothing
End Sub