Office中国论坛/Access中国论坛

标题: 导出数据到Excel如何直接覆盖原来的Excel [打印本页]

作者: yuayua23    时间: 2010-3-21 00:21
标题: 导出数据到Excel如何直接覆盖原来的Excel
以下是chaojianan 将两张表导出到同一Excel的代码,当更新导出的时候出现工作表中表1已经存在的提示,并终止运行,如何直接覆盖原来的Excel呢?
Private Sub Command0_Click()
    Dim cllbdrcx1 As String
    Dim sqlr1 As String
    Dim cllbdrcx2 As String
    Dim sqlr2 As String

    cllbdrcx1 = "产品类别1"
    cllbdrcx2 = "产品类别2"
    sqlr1 = "select * into [Excel 8.0;database=" & CurrentProject.Path & "\TEST.xls]." & cllbdrcx1 & " from 表1 "
    sqlr2 = "select * into [Excel 8.0;database=" & CurrentProject.Path & "\TEST.xls]." & cllbdrcx2 & " from 表2 "

    CurrentProject.Connection.Execute (sqlr1)
    CurrentProject.Connection.Execute (sqlr2)

End Sub
作者: xryacc2    时间: 2010-3-21 12:56
试试:   
sqlr1 = "select * into [Excel 8.0;database=" & CurrentProject.Path & "\TEST.xls]." & cllbdrcx1 & " from 表1 "
CurrentProject.Connection.Execute (sqlr1)
    sqlr2 = "select * into [Excel 8.0;database=" & CurrentProject.Path & "\TEST.xls]." & cllbdrcx2 & " from 表2 "
CurrentProject.Connection.Execute (sqlr2)
我都是这么写的,没有任何问题




欢迎光临 Office中国论坛/Access中国论坛 (http://www.office-cn.net/) Powered by Discuz! X3.3