|
本帖最后由 78361499 于 2013-1-31 10:42 编辑
Private Sub 导出到excel_Click()
On Error GoTo errit
Dim oExcel As Object
Dim oBook As Object
Dim oSheet 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).colums(1).ColumnWidth = 15
'oBook.worksheets(1).row(1).RowHeight = 13.5
'oBook.worksheets(1).range.ColumnWidth = 15
'oBook.worksheets(1).range.RowHeight = 13.5
oBook.worksheets(1).Range("A2:P2").ColumnWidth = 9
oBook.worksheets(1).Range("Q2:U2").ColumnWidth = 18
oBook.worksheets(1).Range("A2:A1000").RowHeight = 13.5
oBook.worksheets(1).Range("A2").CopyFromRecordset Me.主查询子窗体.Form.Recordset
'oBook.ShowDlgOpenFile = ("d:\人才资料查询.xls")
oBook.SaveAs FileName:="c:\人才资料查询.xls"
MsgBox "查询成功导出为c:\人才资料查询.xls"
errexit:
oBook.Close False
oExcel.Quit
Set oBook = Nothing
Set oExcel = Nothing
Exit Sub
errit:
MsgBox "错误号为" & Err.Number & " 错误说明:" & Err.Description
Resume errexit
End Sub
上面代码中“oBook.worksheets(1).Range("A2").CopyFromRecordset Me.主查询子窗体.Form.Recordset”在win7 32位系统上access2007与2010都没问题,但是在有些32位的win7和xp上都出现错误430:类不支持自动化或不支持期望的接口问题比较急,N个论坛上的帖子我都参考过了,转成mdb,引入dll引不了,ado个更换……请高手指点,谢谢
|
|