| 发表于:2007-08-01 15:21:04 楼主 |
小菜提问: 在vb中做了个“导出按钮”,把access库中的数据导出到excel中…… 导出成功后打开c:\excel\gift.xls文件,就闪了下无法打开excel文件 到任务管理器中,才看到有excel.exe进程(此时无excel文件运行), 关闭excel.exe进程后,才能正常打开c:\excel\gift.xls文件…… 请问这是什么问题??该怎么解决呢?? “导出“代码如下 private sub cmdoutput_click() dim cn as new adodb.connection dim rs as new adodb.recordset dim sql as string cn.open "provider=microsoft.jet.oledb.4.0;data source=d:\gift\gift.mdb " sql = "select * from [ly_gift] " rs.source = sql set rs.activeconnection = cn rs.locktype = adlockoptimistic rs.cursorlocation = aduseclient rs.open sql, cn if rs.recordcount < 1 then msgbox "没有数据导出 ", vbokonly + vbcritical, "错误提示 " else if dir( "c:\excel ", vbdirectory) = " " then mkdir ( "c:\excel ") end if if dir( "c:\excel ") <> " " then kill "c:\excel\gift.xls " end if end if dim i as integer dim j as integer dim xlexcel as new excel.application dim xlbook as new excel.workbook dim xlsheet as new excel.worksheet set xlbook = xlexcel.workbooks.add set xlsheet = xlexcel.worksheets.add xlsheet.cells.columns(5).columnwidth = 20 xlsheet.cells(1, 1) = "联名卡号 " xlsheet.cells(1, 2) = "领用 " xlsheet.cells(1, 3) = "日期 " xlsheet.cells(1, 4) = "时间 " xlsheet.cells(1, 5) = "操作员 " for i = 2 to rs.recordcount + 1 for j = 1 to rs.fields.count xlsheet.cells(i, j) = rs.fields.item(j - 1).value next j rs.movenext next i xlbook.saveas fileformat:=xlexcel9795 xlbook.saveas filename:= "c:\excel\gift.xls " rs.close cn.close end sub |
|
|
|
|