2013-09-27 84 views
0

我有VBA腳本來從oracal DB中檢索數據。該腳本使用打開現有的文件,然後在Excel中做一些時尚。問題是有一個彈出消息說:「你想保存更改嗎?」如何避免彈出消息VBA - 彈出消息以保存更改

'open a new worksheet in Excel 
Set objExcel = CreateObject("Excel.Application") 
Set objWorkbook = objExcel.Workbooks.Open("C:\Users\combbn\Desktop\Reportt\Quary_Result.xls") 
Set objSheet1 = objExcel.ActiveWorkbook.Worksheets(1) 
objWorkbook.Activate 

objWorkbook.SaveAs "C:\Desktop\Reportt\Quary_Result3.xls" 
objWorkbook.Application.Quit 
Set objWorkbook = Nothing 

回答

0

objWorkbook.SaveAs "C:\Desktop\Reportt\Quary_Result3.xls", FileFormat:=56 
objWorkbook.Close SaveChanges:=False 
objExcel.Quit 
Set objWorkbook = Nothing 
Set objExcel = Nothing 

更換

objWorkbook.SaveAs "C:\Desktop\Reportt\Quary_Result3.xls" 
objWorkbook.Application.Quit 
Set objWorkbook = Nothing 

還要注意使用的FileFormat的。這些都是在Excel 2007 - 2013年的主要文件格式:

50 = xlExcel12 (Excel Binary Workbook in 2007-2013 with or without macro's, xlsb) 
51 = xlOpenXMLWorkbook (without macro's in 2007-2013, xlsx) 
52 = xlOpenXMLWorkbookMacroEnabled (with or without macro's in 2007-2013, xlsm) 
56 = xlExcel8 (97-2003 format in Excel 2007-2013, xls) 
+0

重播親愛的感謝腳本VBS也不可能知道下面statament objWorkbook.SaveAs「C:\桌面\ Reportt \ Quary_Result3.xls」的FileFormat: = 56我認爲有fileformat問題:= 56 – user2761483

+0

我沒有測試它的VBScript,但我給你的代碼..它會給你任何錯誤? –