Private Sub Command7_Click() Dim Conn1 As New ADODB.Connection Dim Rs1 As New ADODB.Recordset 'On Error GoTo ErrDlog Dim sql1 As String, cnStr1 As String Dim exPath As String, Biao As String
Private Sub reOutExcel(scr As Recordset, fileName As String) Dim xlApp As Excel.Application Dim xlBook As Excel.Workbook Dim xlSheet As Excel.Worksheet Dim r As Long Dim c As Long Set xlApp = CreateObject("Excel.Application") '创建EXCEL对象 If Dir(App.Path & "\" & fileName) = "" Then Set xlBook = xlApp.Workbooks.Add() xlBook.SaveAs App.Path & "\" & fileName Else Set xlBook = xlApp.Workbooks.Open(App.Path & "\" & fileName) End If Set xlSheet = xlBook.Worksheets("sheet1") For c = 0 To scr.Fields.Count - 1 xlSheet.Cells(1, c + 1) = scr.Fields.Item(c).Name Next scr.MoveFirst r = 1 Do While (scr.EOF <> True) For c = 0 To scr.Fields.Count - 1 xlSheet.Cells(r, c + 1) = scr.Fields(c) Next scr.MoveNext r = r + 1 Loop xlBook.Save xlBook.Close Set xlSheet = Nothing Set xlBook = Nothing xlApp.Quit Set xlApp = Nothing End Sub