VB6.0程序调用Excel后,Excel进程无法关闭

2024-11-27 17:29:13
推荐回答(3个)
回答1:

你使用这一段 我一直用都没问题
另外 提醒你一下

注意检查 表格是不是别人先打开你才打开的

这时候是只读方式的时候 你如何判断???

处理好就可以了

再加一句:。。。。 如果你在中间出错的话 没关闭是很正常的 请自己手动从进程里删除

'=======打开远程表格(计划1)开始===============
Set ExcelApp = CreateObject("Excel.Application") '创建EXCEL对象
Set ExcelBook = ExcelApp.Workbooks.Open("y:\计划1.xls")
Set ExcelSheet = ExcelBook.Worksheets("计划1")
'=======打开远程表格(计划1)结束===============

'=======保存并关闭远程表格(计划1)开始==========
ExcelBook.Save
ExcelBook.Close
Set ExcelSheet = Nothing
Set ExcelBook = Nothing
Set ExcelApp = Nothing
'=======保存并关闭远程表格(计划1)结束=========

回答2:

试试
iExcel.Quit False
很可能是Excel卡在保存对话框那里了,如果Excel窗口可见,应该可以看到弹出这个对话框.

回答3:

我的以下下代码能正常结束Excel进程
Option Explicit
Dim iExcel As Excel.Application
Dim iBook As Excel.Workbook
Dim iSheet As Excel.Worksheet

Private Sub Command1_Click()
Set iExcel = CreateObject("Excel.Application")
Set iBook = iExcel.Workbooks.Open(App.Path & "\Setting.xls")
Set iSheet = iBook.Worksheets("Sheet1")
lblA1.Caption = iSheet.Cells(1, 1).Value
lblB1.Caption = iSheet.Cells(1, 2).Value
lblC1.Caption = iSheet.Cells(1, 3).Value
lblD1.Caption = iSheet.Cells(1, 4).Value
lblE1.Caption = iSheet.Cells(1, 5).Value
lblF1.Caption = iSheet.Cells(1, 6).Value
lblA2.Caption = iSheet.Cells(2, 1).Value
lblB2.Caption = iSheet.Cells(2, 2).Value
lblC2.Caption = iSheet.Cells(2, 3).Value
lblD2.Caption = iSheet.Cells(2, 4).Value
lblE2.Caption = iSheet.Cells(2, 5).Value
lblF2.Caption = iSheet.Cells(2, 6).Value
lblA3.Caption = iSheet.Cells(3, 1).Value
lblB3.Caption = iSheet.Cells(3, 2).Value
lblC3.Caption = iSheet.Cells(3, 3).Value
lblD3.Caption = iSheet.Cells(3, 4).Value
lblE3.Caption = iSheet.Cells(3, 5).Value
lblF3.Caption = iSheet.Cells(3, 6).Value
iBook.Close
iExcel.Quit
Set iSheet = Nothing
Set iBook = Nothing
Set iExcel = Nothing

End Sub