类似vlookup的出现的问题
这是一个类似vlookup的代码,有两个问题一直没有解决:1、执行后打开的时候没有写入东西,即保存不了;2、 不能彻底清空内存,执行完成后在任务管理器的进程里面始终存在,要手动清理后才能打开excel文件,请高手们帮忙解决一哈!Dim xlsApp As Excel.Application
Dim xlsBook As Excel.Workbook
Dim xlsSheet As Excel.Worksheet
Dim xlsCells As Excel.Range
Dim StartTime, EndTime, UsedTime As Single
Dim rng As Range
Dim i, j, k, row, col, coll As Double
Dim SL, TL As Double
Dim SQL As String
Set xlsApp = CreateObject("Excel.Application") '创建EXCEL对象
Set xlsBook = xlsApp.Workbooks.Open(TxtFile) '打开已经存在的EXCEL工件簿文件
Set xlsSheet = xlsBook.Worksheets(ComSheet.Text)
Set xlsCells = xlsSheet.Cells
Set rng = xlsSheet.UsedRange
i = rng.Rows.Count
j = rng.Columns.Count
FrmRemind.Show
For col = 1 To j
If xlsCells(1, col) = ComSourceCol.Text Then
SL = col
Exit For
End If
Next
For coll = 1 To j
If xlsCells(1, col) = ComTargetCol.Text Then
TL = coll
Exit For
End If
Next
For row = 2 To i
If rst.State = adStateOpen Then rst.Close
SQL = "SELECT * FROM " & ComTable & " where " & ComField.Text & "='" & xlsSheet.Cells(row, SL) & "'"
rst.Open SQL, Conn, adOpenKeyset, adLockOptimistic
If rst.RecordCount <> 0 Then
xlsCells(row, TL) = rst.Fields(ComSourceField.Text) '执行这句没有问题,但是实际上没有写入,再次打开excel的时候没有更新
End If
Next row
xlsApp.DisplayAlerts = False
xlsBook.Save
xlsBook.Close
Set xlsApp = Nothing
Set xlsBook = Nothing
rst.Close
Conn.Close