|
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
End Sub
这个是导出为EXCEL文件代码,导出路径定死了是d:\查询结果.xls,怎么修改能使保存的时候可以选择保存的路径??就是保存的时候能出现保存对话框! |
|