标题: 导出子窗体记录为EXCEL文件路径问题 [打印本页] 作者: canghe168 时间: 2008-2-19 17:29 标题: 导出子窗体记录为EXCEL文件路径问题 Private Sub cmd导出_Click()
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:\查询结果.xls")
'Docmd.OutputTo acOutputTable, "oBook", acFormatXLS, , TrueCm
MsgBox "查询结果导出到D盘成功"
errexit:
oBook.Close False
oExcel.Quit
Set oBook = Nothing
Set oExcel = Nothing
Exit Sub
errit:
MsgBox "错误号为" & Err.Number & " 错误说明:" & Err.Description
Resume errexit