vb中调用excel时,调用一切正常,但关闭excel时,就出现错误,提示框如下:
excel.exe应用程序错误:
"0x650161fe"指令引用的"0x650161fe"内存,该内存不能为“read”
要终止程序,请单击“确定”。
要调试程序,请单击“取消”。
excel.exe应用程序错误:
"0x650161fe"指令引用的"0x650161fe"内存,该内存不能为“read”
要终止程序,请单击“确定”。
要调试程序,请单击“取消”。
Dim xlBook As Excel.Workbook
Dim xlSheet1 As Excel.Worksheet, xlSheet2 As Excel.Worksheet, xlSheet3 As Excel.Worksheet
Dim xlQuery As Excel.QueryTable, xlQuery1 As Excel.QueryTable, xlQuery2 As Excel.QueryTable
Set xlApp = CreateObject("Excel.Application")
Set xlBook = Nothing
Set xlSheet1 = Nothing
Set xlSheet2 = Nothing
Set xlSheet3 = Nothing
Set xlBook = xlApp.Workbooks().Add
Set xlSheet1 = xlBook.Worksheets("Sheet1")
Set xlSheet2 = xlBook.Worksheets("Sheet2")
Set xlSheet3 = xlBook.Worksheets("Sheet3")
xlApp.Application.Visible = False
xlApp.Quit
Set xlApp = Nothing '"交还控制给Excel
Set xlBook = Nothing
Set xlSheet1 = Nothing
Set xlSheet2 = Nothing
Set xlSheet3 = Nothing
应该可以解决问题
Dim xlApp As New Excel.ApplicationSet xlApp = CreateObject("Excel.Application")既然第一句已经实例化了一个Excel.Application,为什么还要再Create一个Excel?
这样做相当于在内存中实例化了两个Excel.Application,但是你只释放了一个Excel.Application