|
本帖最后由 lyscser 于 2011-5-27 15:00 编辑
在本机可能是删除失败了才导致运行成功的,Save是覆盖保存,应该是应用于保存已经打开文件的修改,新存是SaveAs的吧
具体函数参见下面这个(截取一个函数的一部分,注意注释):
- Set fObject = CreateObject("Scripting.FileSystemObject")
- If Not fObject.FileExists(appointedFile) Then
- Repor micFail,"参数文件不存在:",appointedFile
- Set fObject = Nothing
- End If
-
- If fObject.FileExists(tmpName) Then
- fObject.DeleteFile(tmpName)
- End If
-
- Set ExcelApp = CreateObject("Excel.Application")
- ExcelApp.Application.Visible = False
- ExcelApp.DisplayAlerts = False
- Set newBook = ExcelApp.Workbooks.Open (appointedFile,False,True)--只读模式
- newBook.Worksheets(appointedSheet).Copy
- Set tempBook = ExcelApp.ActiveWorkbook
- tempBook.SaveAs tmpName,1--保存成xls格式
- Set tempBook = Nothing
- ExcelApp.Quit
- Set ExcelApp = Nothing
- DataTable.AddSheet newSheet
- DataTable.ImportSheet tmpName,appointedSheet,newSheet
-
- If fObject.FileExists(tmpName) Then
- fObject.DeleteFile(tmpName)
- End If
复制代码 |
|