如何vb6.0中把查询出来的access数据库中数据导出到Excel表中
例如有一个表tbWorkerInf,怎么将其数据导到excel表中,
希望高手能给点详细的解释,最好写出部分代码,不甚感激啊!!!!
[解决办法]
Private Sub Command1_Click() Dim xlsApp As Object Dim Cnn As New ADODB.Connection Dim Rs As ADODB.Recordset Cnn.ConnectionString = "Provider=microsoft.jet.oledb.4.0;data source=E:\Access DB\Database1.mdb;" If Cnn.State <> ADODB.ObjectStateEnum.adStateClosed Then Cnn.Close Cnn.Open Set Rs = New ADODB.Recordset With Rs Set .ActiveConnection = Cnn .CursorLocation = adUseClient .CursorType = adOpenStatic .LockType = adLockReadOnly .Open "SELECT * FROM tbWorkerInf " End With If Rs.EOF Then Exit Sub Set xlsApp = CreateObject("Excel.Application")' xlsApp.Visible = True xlsApp.Workbooks.Add xlsApp.Sheets("sheet1").Select xlsApp.ActiveSheet.Range("A1").CopyFromRecordset Rs If xlsApp.ActiveWorkbook.Saved = False Then xlsApp.ActiveWorkbook.SaveAs App.Path & "\0.xls" End If xlsApp.Quit Rs.Close Set Rs = Nothing Set xlsApp = NothingEnd Sub