Excel调用的棘手问题,急求解!
我在VB中做了一个EXCEL的调用,用完后关闭Excel,也删除了我创建的临时文件"c:\temp3.xls",但在进程中还有一个Excel,如果此进程不关闭,在下次调用中就会出错,能告诉我如何安全正常的关闭它吗?谢谢!
急!
'===========================================================
Option Explicit
Private Sub Command1_Click()
Dim xlApp As New Excel.Application
Dim xlBook As Excel.Workbook
Dim xlSheet As Excel.Worksheet
Set xlBook = xlApp.Workbooks.Add '创建一个新表
Set xlSheet = xlApp.Workbooks(1).Worksheets(1)
'在新建的EXCEL中(如果只写了一些临时数据它可正常关闭)
With xlApp.ActiveSheet.QueryTables.Add(Connection:= _
"URL;http://www.google.com", Destination _
:=Range("A1"))
.Name = "www.google.com"
.FieldNames = True
.RowNumbers = False
.FillAdjacentFormulas = False
.PreserveFormatting = True
.RefreshOnFileOpen = False
.BackgroundQuery = True
.RefreshStyle = xlInsertDeleteCells
.SavePassword = False
.SaveData = True
.AdjustColumnWidth = True
.RefreshPeriod = 0
.WebSelectionType = xlEntirePage
' .WebSelectionType = xlAllTables '选择目标所在WEB网页的具体位置:表格
.WebFormatting = xlWebFormattingNone
.WebPreFormattedTextToColumns = False
.WebConsecutiveDelimitersAsOne = True
.WebSingleBlockTextImport = False
.WebDisableDateRecognition = True
.Refresh BackgroundQuery:=False
End With
'使用完毕
xlBook.SaveAs FileName:="C:\temp3.xls", FileFormat:= _
xlNormal, Password:="", WriteResPassword:="", ReadOnlyRecommended:=False _
, CreateBackup:=False
Set xlSheet = Nothing
xlBook.RunAutoMacros (xlAutoClose)
xlBook.Close (True) '关闭工作簿
Set xlBook = Nothing
xlApp.Quit '结束EXCEL对象
Set xlApp = Nothing '释放xlApp对象
Kill "c:\temp3.xls"
End Sub