Public Sub SQLToExcel(Rs_Data As ADODB.Recordset) Dim Irowcount As Integer Dim Icolcount As Integer Dim i As Integer
Set xlapp = CreateObject("Excel.Application") Set xlBook = Nothing Set xlSheet = Nothing Set xlBook = xlapp.Workbooks.Add Set xlSheet = xlBook.ActiveSheet
Set myRS = myDBConn.Execute(strSQL)....
rs.Save "c:\" & Format(Now, "yyyymmddhhmmss") & ".dat", adPersistADTG
adPersistADTG 谢谢楼上,只能保存成这两种格式的文件,用excel就打不开了,还不行
Dim Irowcount As Integer
Dim Icolcount As Integer
Dim i As Integer
Set xlapp = CreateObject("Excel.Application")
Set xlBook = Nothing
Set xlSheet = Nothing Set xlBook = xlapp.Workbooks.Add
Set xlSheet = xlBook.ActiveSheet
'显示标题
xlapp.Visible = True
'添加查询语句,导入EXCEL数据
Set xlQuery = xlSheet.QueryTables.Add(Rs_Data, xlSheet.Range("a1")) xlQuery.Refresh
xlQuery.FieldNames = True '显示字段名
xlapp.Application.Visible = True
Set xlapp = Nothing '"交还控制给Excel
Set xlBook = Nothing
Set xlSheet = Nothing
xlapp.QuitEnd Sub导出到Excel的函数
运行SQLToExcel(myrs)?
我接着楼上的写LZ不会用这个函数? dim rs as new adodb.recordset
dim rn as new adodb.connection
...... SQLToExcel rs