你好!你的程序中还需要引用MICROSOFT EXCEL OBJECT LIBRARY。如下为该按钮的代码。后附加入了代码的上传文件。
Private Sub 命令10_Click()
On Error GoTo Err_命令10_Click
Dim xlbook As Excel.Workbook
Set oApp = CreateObject("Excel.Application")
oApp.Visible = True
'Only XL 97 supports UserControl Property
Set xlbook = oApp.Workbooks.Add
With student.Form
For j = 1 To .Recordset.Fields.Count
xlbook.Sheets(1).Cells(1, j) = .Recordset.Fields(j - 1).Name '第一行作为标题行
Next
For i = 1 To .Recordset.RecordCount
For j = 1 To .Recordset.Fields.Count
xlbook.Sheets(1).Cells(i + 1, j) = .Recordset.Fields(j - 1) '第2行为数据行
Next
Next
End With
xlbook.SaveAs "c:\关于" + Trim(student.Form.Recordset.Fields(0)) + "的查询结果.xls"
xlbook.Close
oApp.Quit
Set xlbook = Nothing
Set oApp = Nothing
On Error Resume Next
oApp.UserControl = True
Exit_命令10_Click:
Exit Sub
Err_命令10_Click:
MsgBox Err.Description
Resume Exit_命令10_Click
End Sub
Te7gf0m2.rar
(32.73 KB, 下载次数: 47)
[此贴子已经被作者于2004-7-18 15:06:33编辑过] |