如何导出数据表型子窗体内容到Excel
看到网上的一些导出例子是用 复制拷贝 的方法 把子窗体内容导出,在记录多的时候就很慢
下面是我结合从网上找到的一些资料和查自带帮助 写下的,希望给大家带来方便
Private Sub ImportToExcel()
On Error GoTo errit
Dim oExcel As Object
Dim oBook As Object
Dim i As Integer
Set oExcel = CreateObject("Excel.Application")
Set oBook = oExcel.Workbooks.Add()
Me.子窗体.Form.Recordset.MoveFirst
For i = 0 To Me.子窗体.Form.Recordset.Fields.Count - 1
oBook.Worksheets(1).Cells(1, i + 1).Value = Me.子窗体.Form.Recordset.Fields(i).Name
Next
oBook.Worksheets(1).Range("A2").CopyFromRecordset Me.子窗体.Form.Recordset
oBook.SaveAs ("d:\Test.xls")
MsgBox "导出成功"
errexit:
oBook.Close False
oExcel.Quit
Set oBook = Nothing
Set oExcel = Nothing
Exit Sub
errit:
MsgBox "错误号为" & Err.Number & " 错误说明:" & Err.Description
Resume errexit
End Sub
(责任编辑:admin)