如下代码导出数据到excel后,并弹出EXCEL,但为何总是询问是否保存,还询问两次,让我不得不点击“取消”按钮。怎样才能在弹出EXCEL内容时不提示是否保存对话框? Dim xlApp As New Excel.Application
Dim xlBook As New Excel.Workbook
Dim xlSheet As New Excel.Worksheet On Error GoTo Err_Proc
Set xlApp = CreateObject("Excel.Application")
Set xlBook = xlApp.Workbooks.Add
Set xlSheet = xlBook.Worksheets(1)
xlApp.SheetsInNewWorkbook = 1 '将新建的工作薄数量设为1
xlSheet.Name = Left(tablename, 30)
xlApp.ActiveWindow.Zoom = 100
...........
...导出数据程序.....
...........
xlApp.Visible = True
xlBook.Close
xlApp.Quit
Set xlSheet = Nothing
Set xlBook = Nothing
Set xlApp = Nothing
Err_Proc:
If Not (xlApp Is Nothing) Then xlApp.Quit
Dim xlBook As New Excel.Workbook
Dim xlSheet As New Excel.Worksheet On Error GoTo Err_Proc
Set xlApp = CreateObject("Excel.Application")
Set xlBook = xlApp.Workbooks.Add
Set xlSheet = xlBook.Worksheets(1)
xlApp.SheetsInNewWorkbook = 1 '将新建的工作薄数量设为1
xlSheet.Name = Left(tablename, 30)
xlApp.ActiveWindow.Zoom = 100
...........
...导出数据程序.....
...........
xlApp.Visible = True
xlBook.Close
xlApp.Quit
Set xlSheet = Nothing
Set xlBook = Nothing
Set xlApp = Nothing
Err_Proc:
If Not (xlApp Is Nothing) Then xlApp.Quit
xlBook.Close False
xlApp.Quit
在新工作簿数据写入完毕后,加一句:
xlBook.Saved = True