excel进程在vba结束后不能退出的问题
不晓得有没有前辈遇到过这个问题,vba退出后,进程里始终有excel在运行我写的如下的函数打开excel数据
Function newExcelApp(visible As Boolean) As Excel.Application<BR> Dim xls As Excel.Application<BR> Set xls = New Excel.Application<BR> xls.visible = visible<BR> Set newExcelApp = xls<BR>End Function
Function openExcelBook(app As Excel.Application, name As String) As Excel.workbook<BR> Dim xlbook As Excel.workbook<BR> Set xlbook = app.Workbooks.Open(name)<BR> Set openExcelBook = xlbook<BR>End Function
Function getSheet(workbook As Excel.workbook, name As String) As Excel.worksheet<BR> Dim sheets As Excel.Worksheets<BR> Dim sheet As Excel.worksheet<BR> Dim i As Integer<BR> i = 1<BR> For i = 1 To workbook.sheets.count<BR> <BR> If workbook.sheets.item(i).name = name Then<BR> Set getSheet = workbook.sheets.item(i)<BR> Exit Function<BR> End If<BR> Next<BR>End Function
Set dbXls = newExcelApp(False)<BR> Set dbBook = openExcelBook(dbXls, "C:\Documents and Settings\Administrator\桌面\mywork\pkpm\data.xls")
在UserForm_QueryClose事件里
dbBook.Save<BR> dbBook.Close<BR> dbXls.Quit
但是似乎不行啊
请帮忙解决一下把 我也遇到过类似问题,由于自知很业余,所以没在意 1、将getSheet设置为全局变量
2、在UserForm_QueryClose事件里添加
Set getSheet =nothing
dbBook.Save<BR> dbBook.Close<BR> dbXls.Quit liyuwen发表于2005-5-26 14:21:00static/image/common/back.gif1、将getSheet设置为全局变量
2、在UserForm_QueryClose事件里添加
Set getSheet =nothing
dbBook.Save dbBook.Close d...
<BR>那么是不是异常退出的话就不能关闭了 是的,会在内存里面残留
页:
[1]