|
用Excel查询表应该也可以,不过性能会比拷贝记录集差
没有测试,你自己试试!
- Private Sub Command1_Click()
- Dim xlApp As New Excel.Application
- Dim xlbook As Excel.Workbook
- Dim xlsheet As Excel.Worksheet
- Dim xlQuery As Excel.QueryTable
- Dim rs As New ADODB.Recordset
- Dim I As Long, J As Long
- Set xlbook = xlApp.Workbooks.Add
- xlbook.SaveAs CurrentProject.Path & "\data\A.xlsx"
- rs.CursorLocation = adUseClient
- rs.Open "test1", CurrentProject.Connection, adOpenKeyset, adLockReadOnly
- J = rs.RecordCount
- Set xlsheet = xlbook.Worksheets("sheet1")
- Set xlQuery = xlsheet.QueryTables.Add(rs, xlsheet.Range("A1"))
- xlQuery.Refresh
- MsgBox "导出表成功!" & Chr(13) & "共导出 " & J & " 个表记录到: " & CurrentProject.Path & "\Data 文件夹中"
- rs.Close
- Set rs = Nothing
- Set xlQuery = Nothing
- xlApp.Visible = True
- Set xlsheet = Nothing
- Set xlbook = Nothing
- Set xlApp = Nothing
- End Sub
复制代码 |
|