主题:[讨论]奇怪! VB不能退出EXCEL进程
下面这段代码不知道有什么问题,运行完,EXCEL进程并没有退出,非要关闭我的程序才退出。
如果我不退出程序,再次执行这段代码,就会报错:
实时错误(91):对象变量或With块变量未设置。
Private Sub Command6_Click()
Dim xlApp As Excel.Application
Dim xlBook As Excel.Workbook
Dim xlSheet As Excel.Worksheet
Dim i As Integer
i = 1
Set xlApp = CreateObject("Excel.Application")
xlApp.Visible = False
Set xlBook = xlApp.Workbooks.Open("D:\test.xls")
Set xlSheet = xlBook.Worksheets(1)
Do While i <= ActiveSheet.UsedRange.Rows.Count '[color=800080]将这句中的条件改成 i <= 5 这可以退出[/color]
MsgBox xlSheet.Cells(i, 1)
i = i + 1
Loop
Set xlSheet = Nothing
xlBook.Close
Set xlBook = Nothing
xlApp.Quit
Set xlApp = Nothing
End Sub
请高手们帮忙看看是哪出了问题啊
ActiveSheet.UsedRange.Rows.Count 有什么要释放的吗
如果我不退出程序,再次执行这段代码,就会报错:
实时错误(91):对象变量或With块变量未设置。
Private Sub Command6_Click()
Dim xlApp As Excel.Application
Dim xlBook As Excel.Workbook
Dim xlSheet As Excel.Worksheet
Dim i As Integer
i = 1
Set xlApp = CreateObject("Excel.Application")
xlApp.Visible = False
Set xlBook = xlApp.Workbooks.Open("D:\test.xls")
Set xlSheet = xlBook.Worksheets(1)
Do While i <= ActiveSheet.UsedRange.Rows.Count '[color=800080]将这句中的条件改成 i <= 5 这可以退出[/color]
MsgBox xlSheet.Cells(i, 1)
i = i + 1
Loop
Set xlSheet = Nothing
xlBook.Close
Set xlBook = Nothing
xlApp.Quit
Set xlApp = Nothing
End Sub
请高手们帮忙看看是哪出了问题啊
ActiveSheet.UsedRange.Rows.Count 有什么要释放的吗