|
4#
楼主 |
发表于 2010-7-17 01:38:14
|
只看该作者
估计这个问题是由Office本身的缺陷造成的。也就是说在一个EXCEL内用COPY命令反复拷贝SHEET,就会出现工作表驻留内存不能正常释放的问题。
如果用workbooks.add()就不会有这个问题,不过这样增加的是一个空的SHEET,如果是要拷贝模版,只能打开一个workbooks,让后将某个SHEET反复拷贝到另一个WORKBOOK中去,这样不会有问题。
Dim ExcelApp As Excel.Application
Dim wbSourceBook, wbTargetBook As Workbook
Dim wsSource, wsTarget As Worksheet
Dim xlsPath As String
xlsPath = CurrentProject.Path + "\TEST.xls"
Set ExcelApp = New Excel.Application
Set wbSourceBook = ExcelApp.Workbooks.Open(xlsPath)
Set wbTargetBook = ExcelApp.Workbooks.Add()
ExcelApp.Visible = True
'Application.SheetsInNewWorkbook = 1
'Application.ScreenUpdating = False
Set wsSource = wbSourceBook.Sheets("sheet1")
Dim i
For i = 1 To 3
wsSource.Copy After:=wbTargetBook.Sheets(wbTargetBook.Sheets.Count)
Set wsTarget = wbTargetBook.Sheets(wbTargetBook.Sheets.Count)
Next
wbTargetBook.Sheets("sheet1").Delete
wbTargetBook.Sheets("sheet2").Delete
wbTargetBook.Sheets("sheet3").Delete
'wb.Save
wbSourceBook.Close
Set wsSource = Nothing
Set wbSourceBook = Nothing
Set ExcelApp = Nothing
|
|